Cod sursa(job #2284024)

Utilizator Katherine456719Swan Katherine Katherine456719 Data 16 noiembrie 2018 16:31:31
Problema Multiplu Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.3 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("multiplu.in");
ofstream g("multiplu.out");
const int n=2000000;
struct multiplu
{
    bool c;
    int r,t;
};
multiplu q[n+5];
multiplu temp;
bool f[n];
int cmmmc(int a ,int b)
{
    int r,p;
    p=a*b;
    while(b)
    {
        r=a%b;
        a=b;
        b=r;
    }
    return p/a;
}
int main()
{
    int r1,a,b,m,p,u,ok=0;
    fin>>a>>b;
    m=cmmmc(a,b);
    temp.c=1;
    temp.r=1;
    temp.t=0;
    p=u=1;
    q[u]=temp;
    while(p<=u && !ok)
    {
        r1=((q[p].r)*10+0)%m;
        if(f[r1]==0)
        {
            f[r1]=1;
            temp.c=0;
            temp.r=r1;
            temp.t=p;
            q[++u]=temp;
            if(r1==0)
            {
                ok=1;
                continue;
            }
        }
       r1=(q[p].r*10+1)%m;
        if(f[r1]==0)
        {
            f[r1]=1;
            temp.c=1;
            temp.r=r1;
            temp.t=p;
            q[++u]=temp;
            if(r1==0)
            {
                ok=1;
                continue;
            }
        }
        p++;
    }
    int k[n+5],i=0;
    while(u>0)
    {
        k[++i]=q[u].c;
        u=q[u].t;
    }
    for(int j=i;j>0;j--)
        g<<k[j];
    return 0;
}