Cod sursa(job #2590590)

Utilizator VladTZYVlad Tiganila VladTZY Data 28 martie 2020 14:54:27
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.88 kb
#include <fstream>

using namespace std;

ifstream f("euclid3.in");
ofstream g("euclid3.out");

int a, b, c, tests;

struct multiplu{
    int cmmmdc, x, y;
};

multiplu getCMMDC(int a, int b)
{
    multiplu deReturn;
    int x, y;

    if(b == 0)
    {
        deReturn.cmmmdc = a;
        deReturn.x = 1;
        deReturn.y = 0;

        return deReturn;
    }

    deReturn = getCMMDC(b, a % b);
    x = deReturn.y;
    y = deReturn.x - (a / b) * deReturn.y;
    deReturn.x = x;
    deReturn.y = y;

    return deReturn;
}

int main()
{
    f >> tests;

    while(tests)
    {
        f >> a >> b >> c;

        multiplu rez = getCMMDC(a, b);

        if(c % rez.cmmmdc != 0)
            g << 0 << " " << 0;
        else
            g << rez.x * (c / rez.cmmmdc) << " " << rez.y * (c / rez.cmmmdc);
        g << "\n";

        tests--;
    }
}