Cod sursa(job #2883136)

Utilizator MateiAruxandeiMateiStefan MateiAruxandei Data 1 aprilie 2022 10:44:46
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.71 kb
#include <bits/stdc++.h>

using namespace std;

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

using ll = long long;

inline ll gcdExtins(ll a, ll b, ll &x, ll &y){
    if(b == 0){
        x = 1;
        y = 0;
        return a;
    }
    ll x1, y1;
    ll div = gcdExtins(b, a % b, x, y);
    x1 = y;
    y1 = x - (a / b) * y;
    x = x1, y = y1;
    return div;
}

int main()
{
    int t;
    fin >> t;

    while(t--){
        ll a, b, c;
        fin >> a >> b >> c;
        ll x, y;
        ll d = gcdExtins(a, b, x, y);
        if(c % d)
            fout << 0 << ' ' << 0 << '\n';
        else fout << (c / d) * x << ' ' << (c / d) * y << '\n';
    }
    return 0;
}