Cod sursa(job #2666568)

Utilizator As932Stanciu Andreea As932 Data 2 noiembrie 2020 10:14:52
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.67 kb
#include <bits/stdc++.h>

using namespace std;

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

typedef long long ll;

ll gcdE(ll a, ll b, ll &x, ll &y){
    if(b == 0){
        x = 1;
        y = 0;

        return a;
    }

    ll x0, y0, d;

    d = gcdE(b, a % b, x0, y0);

    x = y0;
    y = x0 - (a / b) * y0;

    return d;
}

int main()
{
    int t;

    fin >> t;

    while(t--){
        ll a, b, c, d, x, y;

        fin >> a >> b >> c;

        d = gcdE(a, b, x, y);

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

    return 0;
}