Cod sursa(job #1617415)

Utilizator firewavesBirsu Ion firewaves Data 27 februarie 2016 13:35:28
Problema Algoritmul lui Euclid extins Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.71 kb
#include <fstream>
using namespace std;
ifstream  fin("euclid3.in");
ofstream fout("euclid3.out");
void euclid( long long a, long long b, long long *c, long long *x, long long *y)
{
    if ( b== 0)
    {
        *c = a;
        *x = 1;
        *y = 0;
    }
    else
    {
        long long x0, y0;
        euclid(b, a%b, c, &x0, &y0);
        *x = y0;
        *y = x0 - (a/b)*y0;
    }
}
int main()
{
    int t;
    long long a, b, c;
    long long x, y;
    fin >> t;
    for (int  i = 1; i <= t; i++ )
    {
        fin >> a >> b >> c;
        euclid(a, b, &c, &x, &y);
        if( x == 1 && y== 0)
            fout<<"0 0\n";
        else  fout << x <<" "<<  y << "\n";
    }
    return 0;
}