Pagini recente » Cod sursa (job #1149591) | Cod sursa (job #1695995) | Cod sursa (job #262839) | Cod sursa (job #716749) | Cod sursa (job #2786356)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("multiplu.in");
ofstream fout("multiplu.out");
int a, b;
queue<int> coada;
int w[2002002];
int prv[2002002];
void sol(int val)
{
if(val == 1)
{
fout << val;
return ;
}
sol(prv[val]);
fout << w[val];
}
int main()
{
fin >> a >> b;
int lcm = a * b / __gcd(a, b);
for(int i = 0; i <= lcm; i ++)
{
w[i] = -1;
}
w[1] = 1;
coada.push(1);
while(!coada.empty())
{
int nod = coada.front();
coada.pop();
int newnod = nod * 10;
int newrest = newnod % lcm;
if(w[newrest] == -1)
{
coada.push(newrest);
w[newrest] = 0;
prv[newrest] = nod;
if(newrest == 0)
break;
}
newnod = nod * 10 + 1;
newrest = newnod % lcm;
if(w[newrest] == -1)
{
coada.push(newrest);
w[newrest] = 1;
prv[newrest] = nod;
if(newrest == 0)
break;
}
}
sol(0);
return 0;
}