Cod sursa(job #2145978)

Utilizator Iorgus08Iorgus Serghei Cicala Iorgus08 Data 27 februarie 2018 18:47:17
Problema Multiplu Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.75 kb
#include <bits/stdc++.h>

using namespace std;

ifstream in("multiplu.in");
ofstream out("multiplu.out");

long a, b, i, t;
int baza[500];

void adaug()
{
    for (i=1; i<=baza[0]; i++)
        if (!baza[i])
        {
            baza[i]=1;
            break;
        }
        else baza[i] = 0;
    if (i>baza[0]) baza[++baza[0]]=1;
}

int main()
{
    in>>a>>b;
    for (baza[0]=baza[1]=1; 1; adaug())
    {
        t=0;
        for (i=baza[0]; i>0; i--)
            t = (t*10+baza[i]) % a;
        if (!t)
        {
            t=0;
            for (i=baza[0]; i>0; i--)
                t=(t*10+baza[i]) % b;
            if (!t) break;
        }

    }
    for (i=baza[0]; i>0; i--)
        out<<baza[i];
    return 0;
}