Cod sursa(job #924162)

Utilizator VladMSBonta vlad valentin VladMS Data 24 martie 2013 10:42:52
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.68 kb
//EUCLID EXTINS
#include <cstdlib>
#include <fstream>
using namespace std;
void gcd(int a, int b, int& d, int& x, int& y)
{
    if(!b)
    {
        x = 1;
        y = 0;
        d = a;
    }
    else {
             int x0, y0;

             gcd(b, a % b, d, x0, y0);
             x = y0;
             y = x0 - (a / b) * y0;
         }
}
int main()
{
    int T, a, b, c, d, x, y;
    ifstream fin("euclid3.in");
    ofstream fout("euclid3.out");
    for(fin >> T; T; --T)
    {
        fin >> a >> b >> c;
        gcd(a, b, d, x, y);
        if(c % d) fout << "0 0\n";
        else      fout << (x * (c / d)) << ' ' << (y * (c / d)) << '\n';
    }
    return 0;
}