Cod sursa(job #926566)
#include<cstdio>
using namespace std;
int u,p,v[100000];
struct queue
{
int c,r,t;
};
queue q[100000];
void afisare()
{
int j,k;
k=0;
v[++k]=u;
while(u>0)
{
u=q[u].t;
v[++k]=u;
}
for(j=k-1;j>0;j--) printf("%d",q[v[j]].c);
printf("\n");
}
int main()
{
freopen("multiplu.in","r",stdin);
freopen("multiplu.out","w",stdout);
int ai,bi,a,b,cmmmc,r;
scanf("%d%d",&a,&b);
ai=a;
bi=b;
while(r)
{
r=a%b;
a=b;
b=r;
}
cmmmc=ai*bi/a;
p=1;
u=1;
q[1].c=1;
q[1].r=1;
q[1].t=0;
for(p=1;p;p++)
{
q[++u].c=0;
q[u].r=(q[p].r*10+q[u].c)%cmmmc;
q[u].t=p;
if(q[u].r==0) {afisare();
break;}
q[++u].c=1;
q[u].r=(q[p].r*10+q[u].c)%cmmmc;
q[u].t=p;
if(q[u].r==0) {afisare();
break;}
}
return 0;
}