Cod sursa(job #2704866)

Utilizator flibiaVisanu Cristian flibia Data 11 februarie 2021 15:20:38
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.72 kb
#include <bits/stdc++.h>
#define ll long long 

using namespace std;

ifstream in("euclid3.in");
ofstream out("euclid3.out");

ll t, a, b, c, x, y, d;

void euclid(ll a, ll b, ll &d, ll &x, ll &y) {
    if (b == 0) {
        d = a;
        x = 1;
        y = 0;
        return;
    }

    ll xx = x, yy = x;
    euclid(b, a % b, d, xx, yy);

    y = xx - (a / b) * yy;
    x = yy;
}

int main() {
    in >> t;
    
    while (t--) {
        in >> a >> b >> c;
        d = 0;
        x = 0;
        y = 0;
        euclid(a, b, d, x, y);

        if (c % d) {
            out << "0 0\n";
        } else {
            out << x * c / d << ' ' << y * c / d << '\n';
        }
    }

    return 0;
}