Pagini recente » Cod sursa (job #2524324) | Cod sursa (job #3245814) | Cod sursa (job #302675) | Cod sursa (job #1117340) | Cod sursa (job #2284013)
#include <fstream>
using namespace std;
ifstream in("multiplu.in");
ofstream out("multiplu.out");
const int nmax=2000000;
struct multiplu {
int c,r,t;
};
multiplu v[nmax+5];
bool f[nmax+5];
int x[nmax+5];
int cmmmc(int a,int b) {
int r,prod;
prod=a*b;
while(b) {
r=a%b;
a=b;
b=r;
}
return prod/a;
}
int main() {
int a,b,m;
in>>a>>b;
m=cmmmc(a,b);
int p,u,ok=1,r,c;
p=u=1;
multiplu temp;
temp.r=1;
temp.c=1;
temp.t=0;
v[u]=temp;
while(p<=u and ok){
for(c=0;c<=1;c++){
r=(v[p].r*10+c)%m;
if(f[r]==0){
f[r]=1;
temp.c=c;
temp.r=r;
temp.t=p;
v[++u]=temp;
if(r==0){
ok=0;
continue;
}
}
}
p++;
}
int cnt=1;
while(u>0){
x[cnt++]=v[u].c;
u=v[u].t;
}
cnt--;
while(cnt)
out<<x[cnt--];
return 0;
}