Cod sursa(job #2313220)

Utilizator ptudortudor P ptudor Data 6 ianuarie 2019 13:36:56
Problema Multiplu Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.95 kb
#include <bits/stdc++.h>
using namespace std;
ifstream in ("multiplu.in");
ofstream out("multiplu.out");
queue <pair<int,int>> q;
int A,B,C;
bitset <2000005>v;
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(int loc)
{
    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,loc;
    in>>A>>B;
    C=(A*B)/get_C();
    q.push({1,1});
    while (!q.empty())
    {
       loc=q.front().second;
       x=q.front().first;
       q.pop();
       if (x==0)
       {
           output(loc);
           return 0;
       }
       if (v[1LL*x*10%C]==0){v[1LL*x*10%C]=1;q.push({1LL*x*10%C,loc*2});}
       if (v[(1LL*x*10+1)%C]==0){v[(1LL*x*10+1)%C]=1;q.push({(1LL*x*10+1)%C,loc*2+1});}

    }
    return 0;
}