Cod sursa(job #116122)

Utilizator DorinOltean Dorin Dorin Data 17 decembrie 2007 20:38:13
Problema Multiplu Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.26 kb
# include <stdio.h>

# define input "multiplu.in"
# define output "multiplu.out"

# define max 2000001

long long n,i,j,rez;
long long x,y,nrc,capat,st;
long long rest[max],val[max];

long long cmmmc(long long a,long long b)
{
    long long x,y,r;
    x = a;
    y = b;
    while(b)
    {
            r = a%b;
            a=b;
            b=r;
    }
    return (x*y)/a;
}

int main()
{
    freopen(input,"r",stdin);
    freopen(output,"w",stdout);
    
    scanf("%lld%lld",&x,&y);
    n = cmmmc(x,y);
    
    x = n;
    while(x)
        x/=10,nrc++;

    val[1] = 1;
    rest[1] = 1;
    st = 1;
    
    
    capat = 1;
    
    while(1)
    {
        if(!rest[(val[st]*10)%n])
        {
           if(!((val[st]*10)%n))
           {
               printf("%lld",val[st]*10);

               return 0;
           }
           val[++capat] = val[st]*10;
           rest[(val[st]*10)%n] = 1;
        }
        if(!rest[(val[st]*10+1)%n])
        {
           if(!((val[st]*10+1)%n))
           {
               printf("%lld",val[st]*10+1);

               return 0;
           }
           val[++capat] = val[st]*10+1;
           rest[(val[st]*10+1)%n] = 1;
        }
        st++;
    }
                
    return 0;
}