Cod sursa(job #2977319)

Utilizator gabriel10tm@gmail.comGabriel Marian [email protected] Data 11 februarie 2023 12:58:44
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.69 kb
#include <bits/stdc++.h>
using namespace std;
#if 1
#define cin fin
#define cout fout
ifstream fin("euclid3.in");
ofstream fout("euclid3.out");
#endif
#define ll int64_t
ll euc(ll a,ll b,ll& x,ll& y){
    if(b==0){
        x = 1;
        y = 0;
        return a;
    }
    ll d,x0,y0;
    ll c = a/b;
    d = euc(b,a%b,x0,y0);
    x = y0;
    y = x0 - c*y0;
    return d;
}
void solve(){
    ll a,b,c;
    cin >> a >> b >> c;
    ll x,y;
    ll d = euc(a,b,x,y);
    if(c%d==0){
        ll cat = c/d;
        cout << x*cat << " " << y*cat << "\n";
    }
    else
        cout << "0 0\n";
}
int main(){
    int t;
    cin >> t;
    while(t--){
        solve();
    }
}