Cod sursa(job #1354678)

Utilizator MaarcellKurt Godel Maarcell Data 21 februarie 2015 22:50:31
Problema Algoritmul lui Euclid extins Scor 20
Compilator cpp Status done
Runda Arhiva educationala Marime 0.64 kb
#include <iostream>
#include <fstream>
#define LL long long int
using namespace std;

LL T,gcd;

void gcdext(LL a, LL b,LL &x,LL &y){
    if (b==0){
        x=1;
        y=0;
        gcd=a;
        return;
    }

    LL x0,y0;
    gcdext(b,a%b,x0,y0);
    x=y0;
    y=x0-y0*(a/b);
}


int main(){
    ifstream fin("euclid3.in");
    ofstream fout("euclid3.out");
    fin >> T;

    LL a,b,c,x,y;
    while (T--){
        fin >> a >> b >> c;
        gcdext(a,b,x,y);
        if (c%gcd){
            fout << "0 0\n";
            return 0;
        }
        fout << x*c/gcd<< " " << y*c/gcd << "\n";
    }

    return 0;
}