Pagini recente » Cod sursa (job #1054480) | moisil_11-12_sim | Cod sursa (job #1634842) | Cod sursa (job #1018145) | Cod sursa (job #115933)
Cod sursa(job #115933)
#include <stdio.h>
const char iname[] = "multiplu.in";
const char oname[] = "multiplu.out";
#define MAXM 2000005
int queue[MAXM];
bool sel[MAXM];
int rest[MAXM];
short int cifra[MAXM];
void print(int r) {
if (r != 1) print(rest[r]);
printf("%d", cifra[r]);
}
int gcd(int a, int b) {
if (!b) return a;
return gcd(b, a % b);
}
int main(void)
{
freopen(iname, "r", stdin);
freopen(oname, "w", stdout);
int A, B;
scanf("%d %d", &A, &B);
int M = A * B / gcd(A, B);
int head, tail, r, X;
sel[1] = true;
cifra[1] = 1;
for (queue[head = tail = 0] = 1; head <= tail; ++ head)
{
X = queue[head];
r = (X * 10) % M;
if (!sel[r])
{
queue[++ tail] = r;
sel[r] = true;
rest[r] = X;
cifra[r] = 0;
}
r ++;
if (r >= M)
r -= M;
if (!sel[r])
{
queue[++ tail] = r;
sel[r] = true;
rest[r] = X;
cifra[r] = 1;
}
}
print(0);
return 0;
}