Cod sursa(job #2642977)

Utilizator stefanvoicaVoica Stefan stefanvoica Data 17 august 2020 23:58:54
Problema Multiplu Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.99 kb
#include <bits/stdc++.h>
using namespace std;
ifstream fin ("multiplu.in");
ofstream fout("multiplu.out");
int a,b,d,from[2000001];
queue<int> nr;

void afis (int x)
{
    if (x!=-1)
    {
        afis(from[x]);
        if ((from[x]*10)%d==x)
        fout<<0;
        else    fout<<1;
    }
}

int main()
{
    fin>>a>>b;
    d=a*b/__gcd(a,b);
    nr.push(1);
    from[1]=-1;
    bool ok=true;
    if (d!=1)
    while (ok)
    {
        int vf=nr.front();
        if (from[(vf*10)%d]==0)
        {
        nr.push((vf*10)%d);
        from[nr.back()]=vf;
        if (nr.back()==0)
            {
                afis(nr.back());
                exit(0);
            }
        }
        if (from[(vf*10+1)%d]==0)
        {
        nr.push((vf*10+1)%d);
        from[nr.back()]=vf;
        if (nr.back()==0)
            {
                afis(nr.back());
                exit(0);
            }
        }
        nr.pop();
    }
    fout<<'\n';
    return 0;
}