Cod sursa(job #2883138)

Utilizator hhhhhhhAndrei Boaca hhhhhhh Data 1 aprilie 2022 10:47:08
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.73 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;
ll t,a,b,c;
void solve()
{
    fin>>a>>b>>c;
    ll cmmdc=__gcd(a,b);
    if(c%cmmdc!=0)
    {
        fout<<"0 0\n";
        return;
    }
    a/=cmmdc;
    b/=cmmdc;
    c/=cmmdc;
    pll Va={1,0};
    pll Vb={0,1};
    pll Vr;
    while(b!=0)
    {
        ll cat=a/b;
        ll r=a%b;
        Vr.first=Va.first-Vb.first*cat;
        Vr.second=Va.second-Vb.second*cat;
        a=b;
        b=r;
        Va=Vb;
        Vb=Vr;
    }
    fout<<Va.first*c<<' '<<Va.second*c<<'\n';
}
int main()
{
    fin>>t;
    while(t--)
        solve();
    return 0;
}