Cod sursa(job #115844)

Utilizator goguGogu Marian gogu Data 17 decembrie 2007 02:31:20
Problema Multiplu Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.89 kb
#include <cstdio>
#define MaxN (1<<21)
#define c(i, j) ((i)*b+(j))

int n, nr, a, b, t[MaxN], cx[MaxN], cy[MaxN], cif[MaxN];
char ok[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;
        cx[nr] = r1;
        cy[nr++] = 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);
    cx[0]=1; cy[0]=1;
    ok[c(1,1)]=0;
    cif[c(1,1)]=1;
    int j=0;
    nr=1;
    while (!ok[0] && j<nr){
          expand(cx[j], cy[j]);
          j++;
    }
    refa(0);
}