Cod sursa(job #2254681)

Utilizator PetyAlexandru Peticaru Pety Data 5 octombrie 2018 19:17:29
Problema Multiplu Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.72 kb
#include <bits/stdc++.h>

using namespace std;

ifstream fin ("multiplu.in");
ofstream fout ("multiplu.out");

const int N = 2000002;
int a, b, p[N], last[N];

void hatz (int x) {
  if (x != 1)
    hatz(p[x]);
  fout << last[x];
}

int main()
{
  fin >> a >> b;
  int nr = a * b / __gcd(a, b);
  for (int i = 0; i < nr; i++)
    last[i] = -1;
  queue <int>q;
  q.push(1);
  last[1] = 1;
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    int y = x * 10 % nr;
    if (last[y] == -1) {
      last[y] = 0;
      p[y] = x;
      q.push(y);
    }
    y = (10 * x + 1) % nr;
    if (last[y] == -1) {
      last[y] = 1;
      p[y] = x;
      q.push(y);
    }
  }
  hatz(0);
  return 0;
}