Cod sursa(job #3163720)

Utilizator Allie28Radu Alesia Allie28 Data 31 octombrie 2023 23:17:49
Problema Multiplu Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.09 kb
#include <vector>
#include <queue>
#include <fstream>
#include <iostream>

using namespace std;

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

const int LMAX = 2000005;
int father[LMAX], cmmdc;
bool ultcif[LMAX];

void gasescnr() {
    queue <int> Q;
    Q.push(1);
    father[1] = -1;
    ultcif[1] = 1;
    while (!Q.empty() && !father[0]) {
        int node = Q.front();
        Q.pop();
        int rest = node*10%cmmdc;
        if (!father[rest]) {
            father[rest] = node;
            Q.push(rest);
        }
        rest = (rest+1)%cmmdc;
        if (!father[rest]) {
            father[rest] = node;
            ultcif[rest] = 1;
            Q.push(rest);
        }

    }
}

void afisnr(int node) {
    if (father[node] != -1) {
        afisnr(father[node]);
    }
    fout<<ultcif[node];
}


int main() {
    int A, B, p, r;
    fin>>A>>B;
    p = A*B;
    while (B) {
        r = A%B;
        A = B;
        B = r;
    }
    cmmdc = p/A;
    gasescnr();
    afisnr(0);



    fin.close();
    fout.close();
    return 0;
}