Pagini recente » Cod sursa (job #2692104) | Cod sursa (job #1946551) | Cod sursa (job #1920557) | Cod sursa (job #2867691) | Cod sursa (job #2736467)
#include <bits/stdc++.h>
using namespace std;
const int NMAX = 2e6;
int a, b, cmmmc, t[NMAX + 1];
bitset<NMAX + 1> v;
inline int Cmmmc(const int X, const int Y) {
return X / __gcd(X, Y) * Y;
}
void bfs() {
queue<int> q;
q.push(1), t[1] = -1, v[1] = 1;
while(!q.empty()) {
const int cx = q.front();
q.pop();
if(!cx) return;
for(int i = 0; i < 2; ++i) {
const int ncx = (cx * 10 + i) % cmmmc;
if(!t[ncx])
t[ncx] = cx,
v[ncx] = i;
q.push(ncx);
}
}
}
inline void afis(const int X = 0) {
if(X == -1) return;
afis(t[X]);
cout<<v[X];
}
int main()
{
freopen("multiplu.in", "r", stdin);
freopen("multiplu.out", "w", stdout);
scanf("%d%d", &a, &b), cmmmc = Cmmmc(a, b);
bfs(), afis();
return 0;
}