Cod sursa(job #2476584)

Utilizator MarianConstantinMarian Constantin MarianConstantin Data 19 octombrie 2019 09:51:55
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.69 kb
#include <iostream>
#include <fstream>
#define ll long long

using namespace std;

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

void gcdExtended(ll a, ll b, ll &x, ll &y, ll &d)  {
    if (!b) {
        d = a;
        x = 1;
        y = 0;
        return;
    }
    gcdExtended(b, a % b, x, y, d);
    ll aux = x;
    x = y;
    y = aux - (a / b) * y;
}

int main() {
    ll n, a, b, c, x, y, d;
    fin >> n;
    for (int i = 0; i < n; ++i) {
        fin >> a >> b >> c;
        gcdExtended(a, b, x, y, d);
        if (c % d == 0)
            fout << x * (c / d) << ' ' << y * (c / d) << '\n';
        else
            fout << "0 0\n";
    }
    return 0;
}