Pagini recente » Cod sursa (job #1040956) | Cod sursa (job #112675) | Cod sursa (job #804014) | Cod sursa (job #910650) | Cod sursa (job #2263123)
#include <bits/stdc++.h>
#define NMAX 2000002
using namespace std;
ifstream fin("multiplu.in");
ofstream fout("multiplu.out");
int pre[NMAX], tip[NMAX],used[NMAX];
string sol;
int main()
{
int a,b,m;
fin>>a>>b;
if( a * b == 1 )
{
fout << "1";
}
else
{
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 )
{
int nod = Q.front();
Q.pop();
for(int cif=0; cif<=1; cif++)
{
int x = (10 * nod + cif) % m;
if( !used[x] )
{
used[x] = 1;
pre[x] = nod;
tip[x] = cif;
Q.push(x);
}
}
}
while( gasit!=-1)
{
sol.push_back('0' + tip[gasit]);
gasit = pre[gasit];
}
fout << sol << '\n';
}
return 0;
}