Cod sursa(job #1726250)

Utilizator tanasaradutanasaradu tanasaradu Data 7 iulie 2016 16:35:40
Problema Multiplu Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.18 kb
#include <bits/stdc++.h>
using namespace std;
bitset<2000005>cif;
bitset<2000005>viz;
int pred[2000005],q[2000005],C;
int cmmmc(int a,int b)
{
    int r,x,y;
    x=a;
    y=b;
    while(b!=0)
    {
        r=a%b;
        a=b;
        b=r;
    }
    return (x*y)/a;
}
void Rezolva()
{
    ofstream fout("multiplu.out");
    int pr,ul,k,x,y;
    pr=ul=1;
    q[ul]=1;
    pred[1]=0;
    cif[1]=1;
    k=1;
    viz[1]=1;
    while(viz[0]==0)
    {
        x=q[pr];
        y=(x*10)%C;
        if(viz[y]==0)
        {
            viz[y]=1;
            q[++ul]=y;
            cif[++k]=0;
            pred[k]=pr;
        }
        if(viz[0]==0)
        {
        y=(x*10+1)%C;
        if(viz[y]==0)
        {
            viz[y]=1;
            q[++ul]=y;
            cif[++k]=1;
            pred[k]=pr;
        }
        }
        pr++;
    }
    stack<int>st;
    while(ul>0)
    {
        st.push(cif[ul]);
        ul=pred[ul];
    }
    while(!st.empty())
    {
        fout<<st.top();
        st.pop();
    }
}
int main()
{
    int a,b;
    ifstream fin("multiplu.in");
    fin>>a>>b;
    C=cmmmc(a,b);
    Rezolva();
    return 0;
}