Cod sursa(job #2502690)

Utilizator Cezar211Popoveniuc Cezar Cezar211 Data 1 decembrie 2019 14:03:51
Problema Algoritmul lui Euclid extins Scor 50
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.66 kb
#include <bits/stdc++.h>
using namespace std;
ifstream fin ("euclid3.in");
ofstream fout ("euclid3.out");
int T, a, b, c;
int gcd(int a, int b, int& x, int& y)
{
    if(a == 0)
    {
        x = 0;
        y = 1;
        return b;
    }
    int x1, y1;
    int d = gcd(b%a, a, x1, y1);
    x = y1-(b/a)*x1;
    y = x1;
    return d;
}
int main()
{
    fin >> T;
    while(T--)
    {
        int x_rez, y_rez;
        fin >> a >> b >> c;
        int d = gcd(a, b, x_rez, y_rez);
        if(c%d!=0)
            fout << "0 0\n";
        else
        {
            fout << x_rez*c/d << ' ' << y_rez*c/d << '\n';
        }
    }
    return 0;
}