Cod sursa(job #2979258)

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

using namespace std;

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

static inline int cmmdc(int a, int b) {
    long long rest = a % b;
    while(rest) {
        a = b;
        b = rest;
        rest = a % b;
    }
    return b;
}

int main() {
    fin >> a >> b;
    m = a * b / cmmdc(a, b);
    q.push(1);
    fr[1] = 1;
    while(!q.empty()) {
        x = q.front();
        if(x % m == 0 || (x * 10) % m == 0 || (x * 10 + 1) % m == 0) break;
        q.push(x * 10);
        q.push(x * 10 + 1);
	q.pop();
    }
    fout << q.front();

    return 0;
}