Cod sursa(job #2171568)

Utilizator RazorBestPricop Razvan Marius RazorBest Data 15 martie 2018 12:45:57
Problema Algoritmul lui Euclid extins Scor 20
Compilator cpp Status done
Runda Arhiva educationala Marime 0.67 kb
#include <fstream>
using namespace std;

ifstream fin("euclid3.in");
ofstream fout("euclid3.out");

int eec(int a, int b, int &x, int &y)
{
    if (a % b == 0)
    {
        x = 0;
        y = 1;
        return b;
    }

    int x2;
    int cmmdc = eec(b, a % b, x2, x);
    y = x2 - x * (a / b);

    return cmmdc;
}

int main()
{
    int T, a, b, c, d, x, y;

    fin >> T;
    while (T--)
    {
        bool invers = false;

        fin >> a >> b >> c;
        d = eec(a, b, x, y);
        if (c % d != 0)
        {
            fout << "0 0\n";
            continue;
        }
       fout << x * c / d << ' ' << y * c / d << '\n';
    }
}