Cod sursa(job #2855860)

Utilizator Constantin.Dragancea Constantin Constantin. Data 22 februarie 2022 23:46:55
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.7 kb
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

void euclid_extins(ll a, ll b, ll& d, ll &x, ll &y){
    if (b == 0){
        d = a;
        x = 1;
        y = 0;
    }
    else {
        ll x0, y0;
        euclid_extins(b, a % b, d, x0, y0);
        x = y0;
        y = x0 - y0 * (a / b);
    }
}

ll t, a, b, c;

int main(){
    ifstream cin("euclid3.in");
    ofstream cout("euclid3.out");
    cin >> t;
    while (t--){
        cin >> a >> b >> c;
        ll x = 0, y = 0, d = 0;
        euclid_extins(a, b, d, x, y);
        
        if (c % d){
            cout << "0 0\n";
        }
        else {
            cout << x * c / d << ' ' << y * c / d << '\n';
        }
    }
    return 0;
}