Cod sursa(job #2520705)

Utilizator armigheGheorghe Liviu Armand armighe Data 9 ianuarie 2020 17:35:33
Problema Multiplu Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.13 kb
#include<fstream>
#include<queue>
using namespace std;
ifstream f("multiplu.in");
ofstream g("multiplu.out");
queue<int>q;
int from[2000002],n;
int cmmdc(int x,int y)
{
    int r=x%y;
    while(r!=0)
    {
        x=y;
        y=r;
        r=x%y;
    }
    return y;
}

void sol(int x)
{
    if(x!=-1)
    {
        sol(from[x]);
        if((from[x]*10)%n==x)
            g<<0;
        else
            g<<1;
    }
}

int main()
{
    int a,b,x,xx;
    f>>a>>b;
    n=a*b/cmmdc(a,b);
    if(n==1)
        g<<1;
    else
    {
        q.push(1);
        from[1]=-1;
        while(20==20)
        {
            xx=q.front();
            q.pop();
            x=xx*10;
            x%=n;
            if(from[x]==0)
            {
                from[x]=xx;
                if(x==0)
                    break;
                q.push(x);
            }
            x=xx*10+1;
            x%=n;
            if(from[x]==0)
            {
                from[x]=xx;
                if(x==0)
                    break;
                q.push(x);
            }
        }
    }
    sol(0);
    return 0;
}