Pagini recente » Cod sursa (job #302615) | Cod sursa (job #963565) | Cod sursa (job #2581854) | Cod sursa (job #219079) | Cod sursa (job #2520705)
#include<fstream>
#include<queue>
using namespace std;
ifstream f("multiplu.in");
ofstream g("multiplu.out");
queue<int>q;
int from[2000002],n;
int cmmdc(int x,int y)
{
int r=x%y;
while(r!=0)
{
x=y;
y=r;
r=x%y;
}
return y;
}
void sol(int x)
{
if(x!=-1)
{
sol(from[x]);
if((from[x]*10)%n==x)
g<<0;
else
g<<1;
}
}
int main()
{
int a,b,x,xx;
f>>a>>b;
n=a*b/cmmdc(a,b);
if(n==1)
g<<1;
else
{
q.push(1);
from[1]=-1;
while(20==20)
{
xx=q.front();
q.pop();
x=xx*10;
x%=n;
if(from[x]==0)
{
from[x]=xx;
if(x==0)
break;
q.push(x);
}
x=xx*10+1;
x%=n;
if(from[x]==0)
{
from[x]=xx;
if(x==0)
break;
q.push(x);
}
}
}
sol(0);
return 0;
}