Cod sursa(job #2171620)

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

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

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

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

    return cmmdc;
}

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

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

        fin >> a >> b >> c;

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