Cod sursa(job #2313215)

Utilizator ptudortudor P ptudor Data 6 ianuarie 2019 13:27:54
Problema Multiplu Scor 30
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.83 kb
#include <bits/stdc++.h>
using namespace std;
ifstream in ("multiplu.in");
ofstream out("multiplu.out");
queue <int> q;
int A,B,C,pred[5000005],fin[5000005],v[2000005],loc;
int get_C()
{
    int a=A,b=B,c;
    while (b)
    {
        c=a%b;
        a=b;
        b=c;
    }
    return a;
}
stack <int>st;
void output()
{
    while (loc)
    {
        st.push(loc%2);
        loc/=2;
    }
    while (!st.empty()){out<<st.top();st.pop();}
    out<<"\n";
    out.close();
    in.close();
}
int main()
{int x;
    in>>A>>B;
    C=(A*B)/get_C();
    q.push(1);
    while (!q.empty())
    {
        loc++;
       x=q.front();
       q.pop();
       if (x==0)
       {
           output();
           return 0;
       }
       q.push(1LL*x*10%C);
       q.push((1LL*x*10+1)%C);

    }
    return 0;
}