Cod sursa(job #2269614)

Utilizator FrequeAlex Iordachescu Freque Data 26 octombrie 2018 11:35:35
Problema Multiplu Scor 10
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.35 kb
#include <bits/stdc++.h>
#define ios ios::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define enter cout << '\n'

using namespace std;

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <int> vi;
typedef vector <pii > vii;
typedef vector <ll> vl;
typedef vector <pll > vll;
typedef queue <int> qi;
typedef queue <pii > qii;
typedef queue <ll> ql;
typedef queue <pll > qll;

const int INF = 1000000000;
const int MOD = 104659;
const int EPSILON = 0.0000000001;
const int NMAX = 1e5 + 5;
const int ABMAX = 2e6 + 5;

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

ql q;
int a, b, m;
bool vis[ABMAX];

int gcd(int x, int y)
{
    if (y == 0) return x;
    return gcd(y, x % y);
}

int main()
{
    fin >> a >> b;
    m = (a * b) / gcd(a, b);

    q.push(1);
    vis[1] = true;
    while (q.front() % m != 0)
    {
        if (!vis[(q.front() * 10) % m])
        {
            vis[(q.front() * 10) % m] = true;
            q.push(q.front() * 10LL);
        }
        if (!vis[(q.front() * 10 + 1) % m])
        {
            vis[(q.front() * 10 + 1) % m] = true;
            q.push(q.front() * 10LL + 1);
        }
        q.pop();
    }

    fout << q.front();

    return 0;
}