Cod sursa(job #1204861)

Utilizator andreey_047Andrei Maxim andreey_047 Data 4 iulie 2014 11:46:22
Problema Algoritmul lui Euclid extins Scor 0
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 t;
int Bomb(int a,int b, int &x, int &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    int xx, yy;
    int d = Bomb(b, a % b, xx, yy);
    x = yy;
    y = xx - (a / b) * yy;
    return d;
}
int main() {
    int a,b,c,x,y,d,i;
    fin >> t;
    while(t--){
        fin >> a >> b >> c;
        d = Bomb(a, b, x, y);
        cout << d <<" ";
        if (c % d)
            fout << "0 0\n";
        else
            fout << x * (c / d) << " " << y * (c / d) << "\n";
    }
    fin.close();
    fout.close();
    return 0;
}