Cod sursa(job #1067554)

Utilizator ELHoriaHoria Cretescu ELHoria Data 26 decembrie 2013 23:32:19
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.65 kb
#include <fstream>

using namespace std;

int gcd(int a,int b,int &x,int &y) {
    if (!b) {
        x = 1;
        y = 0;
        return a;
    }
    
    int ret = gcd(b,a % b,x,y);
    int temp = x;
    x = y;
    y = temp - (a / b) * y; 
    return ret;
}

int main()
{
    ifstream cin("euclid3.in");
    ofstream cout("euclid3.out");
    int testCount, a, b, c;
    int Gcd, x, y;
    for (cin >> testCount;testCount;testCount--) {
        cin >> a >> b >> c;
        Gcd = gcd(a,b,x,y);
        if (c % Gcd) {
            cout << "0 0\n";
        } else {
            cout << x * (c / Gcd) << " " << y * (c / Gcd) << "\n";
        }
    }
    return 0;
}