Pagini recente » Cod sursa (job #560018) | Cod sursa (job #810144) | Cod sursa (job #306079) | Cod sursa (job #172470) | Cod sursa (job #115846)
Cod sursa(job #115846)
#include <cstdio>
#define MaxN (1<<21)
#define c(i, j) ((i)*b+(j))
int n, nr, a, b, t[MaxN], cd[MaxN];
char ok[MaxN], cif[MaxN];
void test(int r1, int r2, int T, int c){
int cod = c(r1, r2);
if (!ok[cod]){
t[cod] = T;
cif[cod] = c;
ok[cod] = 1;
cd[nr++] = c(r1, r2);
}
}
void expand(int x, int y){
int r1=(10*x)%a, r2=(10*y)%b;
test(r1, r2, c(x, y), 0);
test((r1+1)%a, (r2+1)%b, c(x, y), 1);
}
void refa(int c){
if (c!=c(1, 1)) refa(t[c]);
printf("%d", cif[c]);
}
int main()
{
freopen("multiplu.in", "r", stdin);
freopen("multiplu.out", "w", stdout);
scanf("%d %d", &a, &b);
cd[nr++] = c(1,1);
ok[c(1,1)]=0;
cif[c(1,1)]=1;
int j=0;
while (!ok[0] && j<nr){
expand(cd[j]/b, cd[j]%b);
j++;
}
refa(0);
}