Cod sursa(job #2018485)

Utilizator IsacLucianIsac Lucian IsacLucian Data 4 septembrie 2017 23:33:10
Problema Multiplu Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.81 kb
#include <bits/stdc++.h>

using namespace std;

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

int A,B,rest[2000002];
queue<int>q;

int Cmmmc(int x,int y)
{
    int r,a,b;
    a=x;b=y;
    while(y!=0)
    {
        r=x%y;
        x=y;
        y=r;
    }
    return (1LL*a*b)/x;
}

int main()
{
    long long aux,v;
    fin>>A>>B;
    A=Cmmmc(A,B);
    q.push(1);
    rest[1]=1;
    while(!q.empty() && rest[0]==0)
    {
        aux=q.front();
        q.pop();
        aux*=10;
        v=aux%A;
        if(rest[v]==0)
        {
            rest[v]=aux;
            q.push(aux);
        }
        aux++;
        v=aux%A;
        if(rest[v]==0)
        {
            rest[v]=aux;
            q.push(aux);
        }
    }
    fout<<rest[0]<<"\n";
    return 0;
}