Cod sursa(job #2906740)

Utilizator bucketlover413Sodinca Iulia Cristiana bucketlover413 Data 27 mai 2022 10:32:41
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.73 kb
#include <iostream>
#include <fstream>

using namespace std;

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


long long int euclid(long long int a,long long int b, long long int  &x,long long int &y)
{
    if (!b) {

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

int main()
{

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

fin>>nr;
while(nr!=0)
{
    nr--;
    fin>>a>>b>>c;
    d=euclid(a, b, x, y);
    if(c%d)
        fout<<0<<" "<<0<<endl;
    else
        {
        fout<<x*c/d<<" "<<y*c/d<<endl;
        }

}

    return 0;
}