Cod sursa(job #115021)

Utilizator DastasIonescu Vlad Dastas Data 16 decembrie 2007 10:16:22
Problema Multiplu Scor 10
Compilator cpp Status done
Runda preONI 2008, Runda 2, Clasele 11-12 Marime 0.63 kb
#include <cstdio>

FILE *in = fopen("multiplu.in","r"), *out = fopen("multiplu.out","w");

int x, y;

int cmmdc(int a, int b)
{
    if ( b == 0 )
        return a;

    return cmmdc(b, a % b);
}

int ok(long long p)
{
    while ( p )
    {
        int k = p % 10;
        if ( k != 1 && k != 0 )
            return 0;

        p /= 10;
    }

    return 1;
}

int main()
{
    fscanf(in, "%d %d", &x, &y);

    long long k = (x*y) / cmmdc(x, y);
    long long t = 2;

    while ( !ok(k) )
    {
        k = k / (t-1);
        k = k * t;
        ++t;
    }

    fprintf(out, "%lld\n", k);

	return 0;
}