Pagini recente » Cod sursa (job #2753093) | Cod sursa (job #2399102) | Cod sursa (job #3273236) | Cod sursa (job #30326) | Cod sursa (job #2491313)
#include <bits/stdc++.h>
#define NMAX 2000001
using namespace std;
ifstream fin("multiplu.in");
ofstream fout("multiplu.out");
bitset<NMAX> fr;
int p[NMAX],v[NMAX],cif[NMAX];
int cmmmc(int a,int b){
long long p=a,r;
p*=b;
while(b){
r=a%b;
a=b;
b=r;
}
return p/a;
}
void print(int lastpos){
while(lastpos>=0){
fout<<cif[lastpos];
lastpos=p[lastpos];
}
}
int main()
{
int a,b,startpos=0,lastpos=1;
fin>>a>>b;
a=cmmmc(a,b);
if(a==1){
fout<<1;
return 0;
}
p[0]=-1;
v[0]=1;
cif[0]=1;
while(fr[0]==0){
if(fr[(v[startpos]*10)%a]==0){
v[lastpos]=(v[startpos]*10)%a;
fr[(v[startpos]*10)%a]=1;
cif[lastpos]=0;
p[lastpos]=startpos;
if((v[startpos]*10)%a!=0){
lastpos++;
}
else {print(lastpos) ; return 0;}
}
if(fr[(v[startpos]*10+1)%a]==0){
v[lastpos]=(v[startpos]*10+1)%a;
cif[lastpos]=1;
fr[(v[startpos]*10+1)%a]=1;
p[lastpos]=startpos;
if((v[startpos]*10+1)%a!=0){
lastpos++;
}
else {print(lastpos) ; return 0;}
}
startpos++;
}
return 0;
}