Cod sursa(job #2863591)

Utilizator Ionut10Floristean Ioan Ionut10 Data 6 martie 2022 22:15:03
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.65 kb
#include <bits/stdc++.h>
#define ll long long

using namespace std;

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

int t;
ll a, b, c;
ll x, y;

ll euclid(ll a, ll b, ll &x, ll &y)
{
    if ( b == 0 )
    {
        x = 1; y = 0;
        return a;
    }
    ll x1, y1;
    ll 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;
        int 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;
}