Cod sursa(job #2284012)

Utilizator razvanboabesrazvan boabes razvanboabes Data 16 noiembrie 2018 16:12:57
Problema Multiplu Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.09 kb
#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 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 rezultat=0;
    while(u>0){
        rezultat=rezultat*10+v[u].c;
        u=v[u].t;
    }
    int rasp=0;
    while(rezultat){
        rasp=rasp*10+rezultat%10;
        rezultat/=10;
    }
    out<<rasp;
        return 0;
}