Pagini recente » Cod sursa (job #950598) | Cod sursa (job #50441) | Cod sursa (job #2864062) | Cod sursa (job #268089) | Cod sursa (job #2299203)
#include <bits/stdc++.h>
using namespace std;
ifstream in("multiplu.in");
ofstream out("multiplu.out");
const int NMAX = 2000000;
bool used[NMAX+2];
int pre[NMAX+2], tip[NMAX+2];
string sol;
int main()
{
int A,B,M;
in >> A >> B;
if( A * B == 1 ) {
out << "1\n";
return 0;
}
M = A / __gcd(A,B) * B;
queue<int> Q;
Q.push(1);
used[1] = 1;
tip[1] = 1;
pre[1] = -1;
int gasit = 0;
while( !Q.empty() && !gasit ) { /// meh
int nod = Q.front();
Q.pop();
for( int cif : {0, 1} ) {
int x = (10 * nod + cif) % M;
if( used[x] ) continue;
used[x] = 1;
pre[x] = nod;
tip[x] = cif;
Q.push(x);
}
}
while( gasit != -1 ) {
sol.push_back('0' + tip[gasit]);
gasit = pre[gasit];
}
reverse(sol.begin(), sol.end());
out << sol << '\n';
return 0;
}