Cod sursa(job #2979262)

Utilizator Radu_BicliBiclineru Radu Radu_Bicli Data 14 februarie 2023 21:08:32
Problema Multiplu Scor 10
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.81 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);
    while(!q.empty()) {
        x = q.front();
        if(x % m == 0) {
            fout << x;
            return 0;
        }
        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;
}