Cod sursa(job #1878598)

Utilizator AlexTheDagonBogdan Tudor AlexTheDagon Data 14 februarie 2017 12:01:27
Problema Multiplu Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.56 kb
#include <iostream>
#include <fstream>
#include <vector>
#define pb push_back
using namespace std;
ifstream in("multiplu.in");
ofstream out("multiplu.out");
int a,b,c,x,y,d;
vector <int> v[50],sursa[50];
int pozi,pozj,sem,l,sir[40],k,fol[2000005];
long long nr;
int main()
{
    in>>a>>b;
    x=a,y=b;
    while(b)
    {
        c=a%b;
        a=b;
        b=c;
    }
    d=x*y/a;
    v[1].pb(1);
    fol[1]=1;
    sursa[1].pb(1);
    sem=1;
    pozi=1;
    while(sem)
    {
        ++pozi;
        l=-1;
        for(int i=0;i<v[pozi-1].size() && sem==1;++i)
        {
            nr=v[pozi-1][i]*10%d;
            if(fol[nr]==0)
            {
                cout<<"DA";
                ++l;
                v[pozi].pb(nr);
                sursa[pozi].pb(i);
                fol[nr]=-1;
                if(nr==0)
                {
                    sem=0;
                    pozj=l;
                }
                nr=(nr+1)%d;
                if(fol[nr]==0)
                {
                    ++l;
                    v[pozi].pb(nr);
                    sursa[pozi].pb(i);
                    fol[nr]=1;
                    if(nr==0)
                    {
                        sem=0;
                        pozj=l;
                    }
                }
            }
        }
    }
    sir[0]=pozi;
    while(pozi)
    {
        if(fol[v[pozi][pozj]]==1)sir[++k]=1;
        else sir[++k]=0;
        pozj=sursa[pozi][pozj];
        --pozi;
    }
    for(int i=sir[0];i>0;--i)out<<sir[i];
    return 0;
}