Cod sursa(job #2237776)

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

using namespace std;

void gcdExtended(int a,int b,int& d,int& x,int& y) {
    if (!b) {
        d=a;
        x=1;
        y=0;
    } else {
        int x0, y0;
        gcdExtended(b,a%b,d,x0,y0);
        x=y0;
        y=x0-(a/b)*y0;
    }
}

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

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

    return 0;
}