Cod sursa(job #2046328)

Utilizator alittlezzCazaciuc Valentin alittlezz Data 23 octombrie 2017 18:17:28
Problema Algoritmul lui Euclid extins Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.62 kb
#include <bits/stdc++.h>
using namespace std;

int solve(int a, int b, int &x, int &y){
    if(b == 0){
        x = 1;
        y = 0;
        return a;
    }
    int x0, y0;
    int ret = solve(b, a%b, x0, y0);
    x = y0;
    y = x0 - (a/b) * y0;
    return ret;
}

int main()
{
    int T;
    cin >> T;
    while(T--){
        int a, b, c;
        cin >> a >> b >> c;
        int d, x, y;
        d = solve(a, b, x, y);
        if(c%d != 0){
            cout << 0 << ' ' << 0 << '\n';
        }else{
            cout << 1LL * x * c / d << ' ' << 1LL * y * c / d << '\n';
        }
    }
    return 0;
}