Pagini recente » Cod sursa (job #3171288) | Cod sursa (job #3170636) | Cod sursa (job #940072) | Cod sursa (job #414843) | Cod sursa (job #2786357)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("multiplu.in");
ofstream fout("multiplu.out");
int a, b;
queue<int> coada;
bool w[2002002];
bool vis[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);
w[1] = 1;
vis[1] = true;
coada.push(1);
while(!coada.empty())
{
int nod = coada.front();
coada.pop();
int newnod = nod * 10;
int newrest = newnod % lcm;
if(!vis[newrest])
{
coada.push(newrest);
vis[newrest] = true;
w[newrest] = 0;
prv[newrest] = nod;
if(newrest == 0)
break;
}
newnod = nod * 10 + 1;
newrest = newnod % lcm;
if(!vis[newrest])
{
coada.push(newrest);
vis[newrest] = true;
w[newrest] = 1;
prv[newrest] = nod;
if(newrest == 0)
break;
}
}
sol(0);
return 0;
}