Cod sursa(job #3208113)

Utilizator hhhhhhhAndrei Boaca hhhhhhh Data 27 februarie 2024 19:40:09
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.8 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;
ll a,b,c;
void solve()
{
    fin>>a>>b>>c;
    ll g=__gcd(a,b);
    if(c%g!=0)
    {
        fout<<"0 0\n";
        return;
    }
    a/=g;
    b/=g;
    c/=g;
    pll Va={1,0};
    pll Vb={0,1};
    while(b)
    {
        ll cat=a/b;
        ll rest=a%b;
        pll Vr;
        Vr.first=Va.first-cat*Vb.first;
        Vr.second=Va.second-cat*Vb.second;
        Va=Vb;
        Vb=Vr;
        a=b;
        b=rest;
    }
    ll x=Va.first*c,y=Va.second*c;
    fout<<x<<' '<<y<<'\n';
}
int main()
{
    ios_base::sync_with_stdio(false);
    fin.tie(0);
    fin>>t;
    while(t--)
        solve();
    return 0;
}