Pagini recente » Cod sursa (job #2107231) | Cod sursa (job #2038685) | Cod sursa (job #2548036) | Cod sursa (job #2451397) | Cod sursa (job #2264114)
#include <bits/stdc++.h>
#define NMAX 2000002
using namespace std;
ifstream fin("multiplu.in");
ofstream fout("multiplu.out");
int pre[NMAX], up[NMAX];
bool verif[NMAX];
string s;
int main()
{
int a,b,m;
fin>>a>>b;
if( a * b == 1 )
{
fout << "1";
return 0;
}
m = a / __gcd(a,b) * b;
queue<int> Q;
Q.push(1);
verif[1] = 1;
up[1] = 1;
pre[1] = -1;
int gasit = 0;
while( !Q.empty() && !gasit)
{
int nod = Q.front();
Q.pop();
for(int i=0; i<=1; i++)
{
int x = (10 * nod + i) % m;
if( verif[x] )
continue;
verif[x] = 1;
pre[x] = nod;
up[x] = i;
Q.push(x);
}
}
while( gasit != -1 )
{
s.push_back('0' + up[gasit]);
gasit = pre[gasit];
}
reverse(s.begin(), s.end());
fout << s << '\n';
return 0;
}