Pagini recente » Monitorul de evaluare | Cod sursa (job #2642976)
#include <bits/stdc++.h>
using namespace std;
ifstream fin ("multiplu.in");
ofstream fout("multiplu.out");
int a,b,d,from[2000001];
queue<int> nr;
void afis (int x)
{
if (from[x]!=-1)
{
afis(from[x]);
if ((x*10)%d==0)
fout<<1;
else fout<<0;
}
}
int main()
{
fin>>a>>b;
d=a*b/__gcd(a,b);
nr.push(1);
from[1]=-1;
fout<<1;
bool ok=true;
if (d!=1)
while (ok)
{
int vf=nr.front();
if (from[(vf*10)%d]==0)
{
nr.push((vf*10)%d);
from[nr.back()]=vf;
if (nr.back()==0)
{
afis(nr.back());
exit(0);
}
}
if (from[(vf*10+1)%d]==0)
{
nr.push((vf*10+1)%d);
from[nr.back()]=vf;
if (nr.back()==0)
{
afis(nr.back());
exit(0);
}
}
nr.pop();
}
fout<<'\n';
return 0;
}