Cod sursa(job #2404235)

Utilizator minculescualex9Minculescu Alex minculescualex9 Data 12 aprilie 2019 13:50:30
Problema Algoritmul lui Euclid extins Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.73 kb
#include <iostream>
#include <fstream>

using namespace std;

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

long euclid(long a, long b, long &x, long &y){
    long x0, y0, d;

    if(b == 0){
        x = 1;
        y = 0;
        return a;
    }

    d = euclid(b, a % b, x0, y0);
    x = y0;
    y = x0 - (a/b) * y0;
    return d;
}

int T;
long a, b, c;

int main()
{
    fin >> T;

    for(int i = 1; i <= T; ++i){
        long x, y;
        fin >> a >> b >> c;

        long d = euclid(a, b, x, y);

        if(c % d)
            cout << "0 0\n";
        else
            cout << x * (c/d) << " " << y *(c/d) << "\n";
    }


    fin.close();
    fout.close();
    return 0;
}