Cod sursa(job #1452974)

Utilizator CollermanAndrei Amariei Collerman Data 22 iunie 2015 15:00:09
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.7 kb
#include<fstream>
using namespace std;
ofstream fout("euclid3.out");
ifstream fin("euclid3.in");

int t;
long int a, b, c, d, x, y;

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

int main()
{
    fin >> t;
    for(int i=1; i<=t; i++) {
        fin >> a >> b >> c;
        euclid(a, b, x, y);

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

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