Pagini recente » Cod sursa (job #1674754) | Cod sursa (job #2583189) | Cod sursa (job #2368313) | Cod sursa (job #1444293) | Cod sursa (job #1097277)
#include <cstdio>
using namespace std;
bool viz[2000002];
bool v[2000002];
struct QUEUE
{
char c;
int r,pred;
};
QUEUE q[2000002];
void sol(int u)
{
int i=1,l;
while (u>0)
{
v[i]=q[u].c;
i++;
u=q[u].pred;
}
l=i-1;
for (i=l;i>=1;i--)
printf("%d",v[i]);
}
int cmmdc(int a,int b)
{
int r;
while (b!=0)
{
r=a%b;
a=b;
b=r;
}
return a;
}
int cmmmc(int a,int b)
{
return a*b/cmmdc(a,b);
}
int main()
{
freopen("multiplu.in","r",stdin);
freopen("multiplu.out","w",stdout);
int a,b,m,p,u,r;
scanf("%d%d",&a,&b);
m=cmmmc(a,b);
QUEUE temp;
p=u=1;
q[p].c=1;
q[p].r=1;
q[p].pred=0;
viz[1]=1;
while (p<=u)
{
// c=0
r=(q[p].r*10+0)%m;
if (viz[r]==0)
{
viz[r]=1;
temp.c=0;
temp.r=r;
temp.pred=p;
q[++u]=temp;
}
if (r==0)
{
sol(u);
return 0;
}
// c=1
r=(q[p].r*10+1)%m;
if (viz[r]==0)
{
viz[r]=1;
temp.c=1;
temp.r=r;
temp.pred=p;
q[++u]=temp;
}
if (r==0)
{
sol(u);
return 0;
}
p++;
}
return 0;
}