Pagini recente » Cod sursa (job #1668926) | Cod sursa (job #955607) | Cod sursa (job #918868) | Cod sursa (job #924722) | Cod sursa (job #2264148)
#include <bits/stdc++.h>
using namespace std;
ifstream fin ("multiplu.in");
ofstream fout("multiplu.out");
const int N_MAX = 10000000 + 5;
int a, b, M;
int cif[N_MAX], up[N_MAX];
bitset<N_MAX> inq;
queue<int> q;
void show(int x){
if(up[x]){
show(up[x]);
fout << cif[x];
} else
fout << 1;
return;
}
void solve(){
q.push(1); inq[1] = 1;
cif[1] = 1; up[1] = 0;
while(!q.empty()){
int x = q.front();
q.pop();
if(x == 0){
show(0);
//cout << "IN GOD WE TRUST";
return;
}
int mod1 = (x*10)%M;
if(!inq[mod1]){
inq[mod1] = true;
q.push(mod1);
up[mod1] = x;
cif[mod1] = 0;
}
int mod2 = (x*10+1)%M;
if(!inq[mod2]){
inq[mod2] = true;
q.push(mod2);
up[mod2] = x;
cif[mod2] = 1;
}
}
}
int main()
{
fin >> a >> b;
M = (a*b)/__gcd(a,b);
solve();
return 0;
}