Cod sursa(job #2979265)

Utilizator Radu_BicliBiclineru Radu Radu_Bicli Data 14 februarie 2023 21:11:24
Problema Multiplu Scor 20
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.75 kb
#include <bits/stdc++.h>

using namespace std;

ifstream fin("multiplu.in");
ofstream fout("multiplu.out");
long long a, b, m, x;
queue<long long> q;

int main() {
    fin >> a >> b;

    m = a * b;
    long long rest = a % b;
    while(rest) {
        a = b;
        b = rest;
        rest = a % b;
    }
    m /= b;

    q.push(1);
    if(1 % m == 0) {
        fout << 1;
        return 0;
    }
    while(!q.empty()) {
        x = q.front();
        if((x * 10) % m == 0) {
            fout << x * 10;
            return 0;
        }
        q.push(x * 10);
        if((x * 10 + 1) % m == 0) {
            fout << x * 10 + 1;
            return 0;
        }
        q.push(x * 10 + 1);
        q.pop();
    }

    return 0;
}