Cod sursa(job #2404272)

Utilizator minculescualex9Minculescu Alex minculescualex9 Data 12 aprilie 2019 14:30:01
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.74 kb
#include <iostream>
#include <fstream>

using namespace std;

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

void euclid(long a, long b, long &x, long &y, long &d){
    if(b == 0){
        d = a;
        x = 1;
        y = 0;
    }else{
        long x0, y0;

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

int T;
long a, b, c;

int main()
{
    fin >> T;

    for(int i = 1; i <= T; ++i){
        fin >> a >> b >> c;
        long x, y, d;

        euclid(a, b, x, y, d);

        if(c % d)
            fout << "0 0\n";
        else
            fout << x * (c/d) << " " << y * (c/d) << "\n";
    }


    fin.close();
    fout.close();
    return 0;
}