Cod sursa(job #3161544)

Utilizator profinfo114Prof Info profinfo114 Data 27 octombrie 2023 14:38:23
Problema Multiplu Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.96 kb
#define _GLIBCXX_FILESYSTEM
#include <bits/stdc++.h>
#define MAX 2000002
using namespace std;
int a,b,cm;
int tata[MAX],cif[MAX],vf[MAX];

ifstream fin("multiplu.in");
ofstream fout("multiplu.out");

void reconstruct(int val){
    if(val == -1){
        return ;
    }
    reconstruct(tata[val]);
    fout << cif[val];
}

int main()
{
    fin >> a >> b;
    cm = (a/__gcd(a, b))*b;
    queue<int> cd;
    cd.push(1);
    tata[1] = -1;
    cif[1] = 1;
    vf[1] = 1;
    while(!cd.empty()){
        int nod = cd.front();
        for(int i = 0; i < 2; i++){
            int vecin = (nod*10+i)%cm;
            if(vf[vecin] == 0){
                tata[vecin] = nod;
                vf[vecin] = 1;
                cif[vecin] = i;
                if(vecin == 0){
                    reconstruct(vecin);
                    exit(0);
                }
                cd.push(vecin);
            }
        }
        cd.pop();
    }
    return 0;
}