Cod sursa(job #2928928)

Utilizator Luka77Anastase Luca George Luka77 Data 24 octombrie 2022 11:16:49
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");

typedef long long ll;
int tt;

inline void euclid(ll a, ll b, ll &d, ll &x, ll &y)
{
    if(!b)
    {
        d = a;
        x = 1;
        y = 0;
    }
    else
    {
        ll x0, y0;
        euclid(b, a%b, d, x0, y0);
        x = y0;
        y = x0 - (a/b)*y0;
    }
}

inline void solve()
{
    ll a, b, c, d, x, y;
    fin >> a >> b >> c;
    euclid(a,b,d,x,y);
    if(c%d)
    {
        fout << "0 0\n";
    }
    else
    {
        fout << x*(c/d) << ' ' << y*(c/d) << '\n';
    }
}

int main()
{
    fin >> tt;
    while(tt--)
    {
        solve();
    }
}