Cod sursa(job #2557097)

Utilizator whothefuckareunicu buliga whothefuckareu Data 25 februarie 2020 15:11:35
Problema Algoritmul lui Euclid extins Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.87 kb
#include <bits/stdc++.h>

using namespace std;

#define ll int
#define INF 1234567890
#define N (int)(2e5 + 5)
ifstream fin("euclid3.in");
ofstream fout("euclid3.out");
struct sol{
ll x, y;
};
sol gcd(ll a, ll b, ll x, ll y, ll x1, ll y1)
{
   if(!b) return {x, y};
   ll q = a / b;
   ll x0 = x - q * x1, y0 = y - q * y1;
   return gcd(b, a % b, x1, y1, x0, y0);
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t;
    fin >> t;
    for(int i = 1; i <= t; ++i)
    {
        ll a, b, c;
        fin >> a >> b >> c;
        a = abs(a), b = abs(b);
        sol s;
        ll cmmdc = (ll) __gcd(a, b);
        if(c % cmmdc == 0){
        s = gcd(a, b, 1, 0, 0, 1);
        fout << s.x * (c / cmmdc) << " " << s.y * (c / cmmdc)<< "\n";
        } else fout << "0 0\n";
    }
    fin.close();
    fout.close();
    return 0;
}