Cod sursa(job #2974463)

Utilizator Ionut10Floristean Ioan Ionut10 Data 4 februarie 2023 09:41:32
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.71 kb
#include <fstream>

using namespace std;

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

int t;
long long a, b, c;

long long euclid(long long a, long long b, long long& x, long long& y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    long long x1, y1;
    long long d = euclid(b, a % b, x1, y1);
    x = y1;
    y = x1 - y1 * (a / b);
    return d;
}
int main()
{
    fin >> t;
    while ( t-- )
    {
        fin >> a >> b >> c;
        long long x = 0; long long y = 0;
        long long d = euclid(a, b, x, y);
        if ( c % d != 0 ) fout << "0 0" << '\n';
        else fout << x * c / d << " " << y * c / d << '\n';
    }
    return 0;
}