Cod sursa(job #2043115)

Utilizator Cristi_ChiraChira Cristian Cristi_Chira Data 19 octombrie 2017 17:28:33
Problema Multiplu Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.05 kb
#include <iostream>
#include <fstream>
#include <numeric>
#include <stdio.h>
#define dm 2000005
using namespace std;
ifstream fin("multiplu.in");
ofstream fout("multiplu.out");
int a, b, m, ca, cb, v[dm], g[dm], rez[dm], k[dm], ls[dm], mc, x ,y, sum    ;
int gcd(int a, int b) {

    return b == 0 ? a : gcd(b, a % b);

}
void rz(){
    int cnt = 0;
    v[1] = 1, g[1] = 1, ls[1] = 1, k[1] = 0;
    x = 1, y = 1;
    while(x <= y)
    {
        for( int i = 0; i <= 1; i++)
        {
            sum = (v[x] * 10 + i) % mc;
            if(!g[sum]){
                y++;
                v[y] = sum, g[sum] = 1, k[y] = x, ls[y] = i;
            }
            if(!sum)
            {
                x = y + 1;
                break;
            }
        }
        x++;
    }
    while(y)
    {
        rez[++cnt] = ls[y];
        y = k[y];
        //cout<< rez[cnt];
    }
    for(int i = cnt; i >= 1; i--)
        fout<< rez[i];
    return;
}
int main()
{
    fin >> a >> b;
    mc = a * b/gcd(a, b);
    rz();
    return 0;
}