Cod sursa(job #2145692)

Utilizator CiprianC11Constantinescu Ciprian CiprianC11 Data 27 februarie 2018 15:52:38
Problema Multiplu Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.43 kb
#include <cstdio>

using namespace std;

int m(int a, int b) { if(a > b) return a; return b; }

class HugeN
{
private :
    int x[100];
public :
    HugeN(int k)
    {
        x[0] = 0;
        for(int i = 1; i < 100; i++)
        {
            x[i] = 0;
        }
        do
        {
            x[++x[0]] = k % 10;
            k /= 10;
        }
        while(k);
    }
    void print()
    {
        for(int i = x[0]; i >= 1; i--)
        {
            printf("%d", x[i]);
        }
    }
    bool ver()
    {
        for(int i = 1; i <= x[0]; i++)
        {
            if(x[i] > 1) return 0;
        }
        return 1;
    }
    void add(const HugeN &other)
    {
        int i, t;
        x[0] = m(x[0], other.x[0]);
        for(t = 0, i = 1; i <= x[0]; i++)
        {
            t = x[i] + other.x[i] + t;
            x[i] = t % 10;
            t /= 10;
        }
        if(t)
        {
            x[0]++;
            x[x[0]] = t;
        }
    }
};

int cmmdc(int a, int b)
{
    int c;
    while(b)
    {
        c = a % b;
        a = b;
        b = c;
    }
    return a;
}

int main()
{
    freopen("multiplu.in", "r", stdin);
    freopen("multiplu.out", "w", stdout);
    int a, b;
    scanf("%d%d", &a, &b);
    HugeN x(a * b / cmmdc(a, b));
    HugeN mult(a * b / cmmdc(a, b));
    while(!x.ver())
    {
        x.add(mult);
    }
    x.print();
    return 0;
}