Cod sursa(job #3141604)

Utilizator Luijika_programatorulBursuc Luigi Luijika_programatorul Data 14 iulie 2023 19:42:01
Problema Multiplu Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.09 kb
#include <bits/stdc++.h>
#define ll long long
#define ull unsinged ll
using namespace std;
ifstream fin("multiplu.in");
ofstream fout("multiplu.out");
int f[2000001];
int v[2000001];
int uc[2000001];
int cmmmc(int a, int b)
{
    int gcd = __gcd(a, b);
    return (a / gcd) * b;
}
void print(int ind)
{
    if (ind == 1)
    {
        fout << 1;
        return;
    }
    print(v[ind]);
    fout << uc[ind];
}
int main()
{
    int a, b;
    fin >> a >> b;
    int c = cmmmc(a, b);
    queue<int> q;

    q.push(1);
    f[1] = 1;
    while (!q.empty())
    {
        int top = q.front();
        q.pop();
        if (f[((top * 10) % c)] == 0)
        {
            q.push(((top * 10) % c));
            f[(top * 10) % c] = 1;
            v[(top * 10) % c] = top;
            uc[(top * 10) % c] = 0;
        }
        if (f[((top * 10 + 1) % c)] == 0)
        {
            q.push((top * 10 + 1) % c);
            f[(top * 10 + 1) % c] = 1;
            v[(top * 10 + 1) % c] = top;
            uc[(top * 10 + 1) % c] = 1;
        }
    }
    print(0);
    return 0;
}