Cod sursa(job #899158)

Utilizator mads2194FMI - Andrei Stroe mads2194 Data 28 februarie 2013 13:08:32
Problema Multiplu Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.93 kb
#include<cstdio>
#include<vector>
#include<queue>

using namespace std;

//#define N 7502

int sol;
int a,b;

//int d[N],F[N],P[N];

queue <int> q;

int cmmdc(int x,int y)
{
    if(y) return (y,x%y);
    return x;
}

int cmmmc(int x,int y)
{
    return x*y/cmmdc(x,y);
}

void run()
{
    int m,x,y;
    m=cmmdc(a,b);

    q.push(1);
    while(!q.empty())
        {
            if(sol) break;
            x=q.front();
            q.pop();

            y=x*10;
            if(y%m>0)
                {
                    q.push(y);
                }
            else sol = y;

            y=x*10+1;
            if(y%m>0)
                {
                    q.push(y);
                }
            else sol = y;
        }

    printf("%d",sol);
}

int main()
{
	freopen("multiplu.in","r",stdin);
	freopen("multiplu.out","w",stdout);

	scanf("%d %d",&a,&b);

	run();

	return 0;
}