Cod sursa(job #1729425)

Utilizator bogdanmarin69Bogdan Marin bogdanmarin69 Data 14 iulie 2016 18:08:17
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.64 kb
#include <fstream>
using namespace std;
ifstream cin("euclid3.in");
ofstream cout("euclid3.out");
int euclid(int a, int b, int &x, int &y) {
    if(b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    int d = euclid(b, a%b, x, y);
    int aux = x;
    x = y;
    y = aux - y * (a/b);
    return d;
}
int main()
{
    int t;
    cin >> t;
    while(t--) {
        int a, b, c, d, x, y;
        cin >> a >> b >> c;
        d = euclid(a, b, x, y);
        if(c % d != 0) {
            cout << "0 0\n";
        } else {
            cout << x * (c / d) << ' ' << y * (c / d) << '\n';
        }
    }
    return 0;
}