Cod sursa(job #2490364)

Utilizator andu2006Alexandru Gheorghies andu2006 Data 10 noiembrie 2019 10:41:16
Problema Multiplu Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.78 kb
#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 main()
{
    int a,b,startpos=0,lastpos=1;
    fin>>a>>b;
    v[0]=1;
    while(fr[0]==0){
        if(fr[(v[startpos]*10)%a]==0){
            v[lastpos]=(v[startpos]*10)%a;
            cif[lastpos]=0;
            p[lastpos]=firstpos;
            lastpos++;
        }
        if(fr[(v[startpos]*10)%a+1]==0){
            v[lastpos]=(v[startpos]*10+1)%a;
            cif[lastpos]=0;
            p[lastpos]=firstpos;
            lastpos++;
        }
        startpos++;
    }
    lastpos--;
    while(lastpos){
        fout<<cif[lastpos];
        lastpos=p[lastpos];
    }
    return 0;
}