Cod sursa(job #2705721)

Utilizator hhhhhhhAndrei Boaca hhhhhhh Data 13 februarie 2021 10:41:09
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.83 kb
#include <bits/stdc++.h>

using namespace std;
ifstream fin("euclid3.in");
ofstream fout("euclid3.out");
typedef long long ll;
typedef pair<ll,ll> pll;
int t;
void solve()
{
    ll a,b,c;
    fin>>a>>b>>c;
    ll cmmdc=__gcd(__gcd(a,b),c);
    a/=cmmdc;
    b/=cmmdc;
    c/=cmmdc;
    pll Va={1,0},Vb={0,1},Vr={0,0};
    while(b)
    {
        ll cat=a/b;
        ll r=a%b;
        Vr.first=Va.first-cat*Vb.first;
        Vr.second=Va.second-cat*Vb.second;
        a=b;
        b=r;
        Va=Vb;
        Vb=Vr;
    }
    if(a!=1)
    {
        fout<<0<<" "<<0<<'\n';
        return;
    }
    ll x=Va.first*c;
    ll y=Va.second*c;
    fout<<x<<" "<<y<<'\n';
}
int main()
{
    ios_base::sync_with_stdio(false);
    fin.tie(0);
    fout.tie(0);
    fin>>t;
    while(t--)
        solve();
    return 0;
}