Cod sursa(job #2147318)

Utilizator Chirita_MateiChirita Matei Chirita_Matei Data 28 februarie 2018 17:16:14
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.74 kb
#include <fstream>

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

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

    gcd(b, a%b, d, x, y);
    int aux = x;
    x = y;
    y = aux - (a/b)*y;
}

int main()
{
    int n, a, b, c;
    int d = 0;
    int x = 0;
    int y = 0;

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

        if(c%d) {
            fout << 0 << ' '<< 0<<'\n';
        }

        else{
            fout << x * (c/d) << ' ' << y * (c/d) << '\n';
        }
    }
    return 0;
}