Cod sursa(job #3296941)

Utilizator mcrg05Craciunescu Mihnea Gabriel mcrg05 Data 19 mai 2025 10:18:17
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;

int64_t gcd(int64_t a, int64_t b, int64_t &x, int64_t &y) {   
    if (b == 0){
        x = 1;
        y = 0;
        return a;
    }
    else{
        int64_t x1, y1, d = gcd(b, a % b, x1, y1);
        x = y1;
        y = x1 - (a / b) * y1;
        return d;
    }
}
int main(){
    freopen("euclid3.in", "r", stdin);
    freopen("euclid3.out", "w", stdout);
    int64_t t, a, b, c, d, x, y;
    cin >> t;
    for (int64_t i = 0; i < t; i++){
        cin >> a >> b >> c;
        d = gcd(a, b, x, y);
        if (c % d != 0) {
            cout << "0 0\n";
        }
        else{
            cout << x * (c / d) << " " << y * (c / d) << "\n";
        }
    }
    return 0;
}