Cod sursa(job #2215923)

Utilizator vladm98Munteanu Vlad vladm98 Data 24 iunie 2018 12:25:19
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.76 kb
#include <bits/stdc++.h>

using namespace std;

void euclidExtins (long long a, long long b, long long &x, long long &y, long long &d) {
    if (b == 0) {
        x = 1;
        y = 0;
        d = a;
        return ;
    }
    euclidExtins(b, a % b, x, y, d);
    long long newX = y;
    long long newY = x - y * (a / b);
    x = newX;
    y = newY;
}

int main()
{
    freopen ("euclid3.in", "r", stdin);
    freopen ("euclid3.out", "w", stdout);
    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        long long a, b, c, x, y, d;
        cin >> a >> b >> c;
        euclidExtins(a, b, x, y, d);
        if (c % d) {
            cout << "0 0\n";
        }
        else {
            cout << x * (c / d) << ' ' << y * (c / d) << '\n';
        }
    }
    return 0;
}