Cod sursa(job #2355455)

Utilizator TyFrostbyteIon Robert-Gabriel TyFrostbyte Data 26 februarie 2019 09:07:49
Problema Algoritmul lui Euclid extins Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.61 kb
#include <fstream>
#include <iostream>

#define ll long long

using namespace std;

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

pair<ll,ll> keter(ll a, ll b){
    if(b==0)
        return {1,0};
    auto p = keter(b, a%b);
    return {p.second, p.first - a / b * p.second};
}

int main() {

    ll n;
    fin>>n;
    for(ll i=0;i<n;i++){
        ll a,b,c;
        fin>>a>>b>>c;

        auto p = keter(a,b);
        ll x = p.first, y = p.second;

        ll d = a*x + b*y;

        if(c%d)
            cout<<"0 0\n";
        else
            cout<< x * (c/d) << " " << y * (c/d)<< "\n";
    }

    return 0;
}