Cod sursa(job #2848093)

Utilizator armand09Armand Miron armand09 Data 12 februarie 2022 09:50:39
Problema Algoritmul lui Euclid extins Scor 60
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.98 kb
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define FASTIO ios::sync_with_stdio(false) , cin.tie(0) , cout.tie(0)

ifstream fin("euclid3.in");
ofstream fout("euclid3.out");
#define LL long long
#define pii pair<int , int>
#define sz(a) ((int)((a).size()))
const unsigned int MAX = 1e2+1;
inline void euclid(LL a , LL b ,LL & d, LL & x ,LL & y)
{
    if(b == 0)
    {
        d = a;
        x = 1, y = 1;
    }
    else
    {
        LL x1 , y1;
        euclid(b , a % b , d, x1 , y1);
        x = y1;
        y = x1 - a / b * y1;
    }
}
LL T;
int32_t main()
{
    FASTIO;
    fin>>T;
    while(T--)
    {
        LL a, b , c;
        LL x1=0 , x2 =0, d;
        fin>>a>>b>>c;
        d = __gcd(a,b);
        if(c%d==0)
        {
            euclid(a,b,d,x1,x2);
            fout<<x1*c/d<<' '<<x2*c/d<<'\n';
        }
        else
          fout<<0<<' '<<0<<'\n';
    }
}