Pagini recente » Cod sursa (job #2655905) | Cod sursa (job #688275) | Cod sursa (job #644605) | Cod sursa (job #1671422) | Cod sursa (job #3163720)
#include <vector>
#include <queue>
#include <fstream>
#include <iostream>
using namespace std;
ifstream fin("multiplu.in");
ofstream fout("multiplu.out");
const int LMAX = 2000005;
int father[LMAX], cmmdc;
bool ultcif[LMAX];
void gasescnr() {
queue <int> Q;
Q.push(1);
father[1] = -1;
ultcif[1] = 1;
while (!Q.empty() && !father[0]) {
int node = Q.front();
Q.pop();
int rest = node*10%cmmdc;
if (!father[rest]) {
father[rest] = node;
Q.push(rest);
}
rest = (rest+1)%cmmdc;
if (!father[rest]) {
father[rest] = node;
ultcif[rest] = 1;
Q.push(rest);
}
}
}
void afisnr(int node) {
if (father[node] != -1) {
afisnr(father[node]);
}
fout<<ultcif[node];
}
int main() {
int A, B, p, r;
fin>>A>>B;
p = A*B;
while (B) {
r = A%B;
A = B;
B = r;
}
cmmdc = p/A;
gasescnr();
afisnr(0);
fin.close();
fout.close();
return 0;
}