Cod sursa(job #3293285)

Utilizator robertcosacCosac Robert-Mihai robertcosac Data 11 aprilie 2025 11:50:22
Problema Multiplu Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.97 kb
#include <bits/stdc++.h>
using namespace std;
ifstream f("multiplu.in");
ofstream g("multiplu.out");
int a, b, d, from[2000009];
queue <int> q;
void afis (int x)
{
    if (x==-1) return;
    afis (from[x]);
    if (from[x]*10%d==x) g << 0;
    else g << 1;
}
int main ()
{
    f >> a >> b;
    d=a*b/__gcd(a,b);
    if (d==1)
    {
        g << 1;
        exit(0);
    }
    from[1]=-1;
    q.push(1);
    while (true)
    {
        int nr=q.front();
        if (from[nr*10%d]==0)
        {
            from[nr*10%d]=nr;
            q.push (nr*10%d);
            if (nr*10%d==0)
            {
                afis (nr*10%d);
                exit(0);
            }
        }
        if (from[(nr*10+1)%d]==0)
        {
            q.push ((nr*10+1)%d);
            from[(nr*10+1)%d]=nr;
            if ((nr*10+1)%d==0)
            {
                afis ((nr*10+1)%d);
                exit(0);
            }
        }
        q.pop();
    }
}