Cod sursa(job #2237773)

Utilizator radu.leonardoThe Doctor radu.leonardo Data 3 septembrie 2018 01:17:00
Problema Algoritmul lui Euclid extins Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.63 kb
#include <fstream>

using namespace std;

int gcdExtended(int a, int b, int & x, int & y) {
    if (a == 0) {
        x = 0;
        y = 1;
        return b;
    }
    int x1, y1;
    int d = gcdExtended(b % a, a, x1, y1);
    x = y1 - (b / a) * x1;
    y = x1;
    return d;
}

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

    int t;
    fin>>t;
    while(t--) {
        int a,b,c,x,y,d;
        fin>>a>>b>>c;
        d=gcdExtended(a,b,x,y);
        if(c%d)
            fout<<0<<' '<<0<<'\n';
        else
            fout<<(x*c)%d<<' '<<(y*c)%d<<'\n';
    }

    return 0;
}