Cod sursa(job #1354939)

Utilizator alex.vasiuVasiu Alexandru alex.vasiu Data 22 februarie 2015 11:05:10
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.73 kb
#include <fstream>

using namespace std;
ifstream f("euclid3.in");
ofstream g("euclid3.out");
void euclid( long long int a,  long long int b,  long long int *d, long long int *x,  long long int *y)
{
    if (b == 0)
    {
        *d = a;
        *x = 1;
        *y = 0;
    }
    else
    {
        long long int x0, y0;
        euclid(b, a % b,d, &x0, &y0);
        *x = y0;
        *y = x0 - (a / b) * y0;
    }
}
int main()
{
    int n;
    f>>n;
    for(int i=1; i<=n; i++)
    {
        long long int a,b,c;
        f>>a>>b>>c;
         long long int x,y,d;
        euclid(a,b,&d,&x,&y);
        if(c%d)
            g<<"0 0\n";
        else
            g<<x*c/d<<" "<<y*c/d<<"\n";
    }
    g.close();
}