Cod sursa(job #2900035)

Utilizator matwudemagogul matwu Data 9 mai 2022 22:42:00
Problema Algoritmul lui Euclid extins Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.58 kb
#include <bits/stdc++.h>
using namespace std;
int n, a, b, c;
int gcd(int a, int b, int &x, int &y){

    if(b == 0){
        x = 1;
        y = 0;
        return a;
    }
    else{
        int x1 , y1;
        int g = gcd(b, a % b, x1, y1);

        x = y1;
        y = x1 - y1 * (a / b);
        return g;
    }
}
int main(){

    cin >> n;
    while(n){
        n --;
        cin >> a >> b >> c;
        int x, y;
        int g = gcd(a, b, x, y);

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