Cod sursa(job #2574710)

Utilizator petrisorvmyVamanu Petru Gabriel petrisorvmy Data 6 martie 2020 09:08:05
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.12 kb
#include <bits/stdc++.h>
#define FILE_NAME "euclid3"
#define fast ios_base :: sync_with_stdio(0); cin.tie(0);
#pragma GCC optimize("O3")
#define NMAX 1000010 + 100
using namespace std;

ifstream f(FILE_NAME ".in");
ofstream g(FILE_NAME ".out");

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef pair<ll,ll> llp;
typedef pair<ld,ld> pct;

const ll inf = 1LL << 60;
const ll mod = 1e9 + 7;
const ld eps = 1e-9;


void add(ll &a , ll b)
{
    a += b;
    a %= mod;
}

void sub(ll &a, ll b)
{
    a = (a - b + mod) % mod;
}

ll gcd(ll a, ll b, ll &x, ll &y)
{
    if(b == 0)
    {
        x = 1;
        y = 0;
        return a;
    }
    ll v = gcd(b, a % b, x, y);
    ll cy = y;
    y = x - (a / b) * y;
    x = cy;
    return v;
}
ll t;
int main()
{
    f >> t;
    while(t--)
    {
        ll a, b, c, x, y;
        f >> a >> b >> c;
        ll v = gcd(a,b,x,y);
        if(c % v == 0)
            g << x * (c / v) << ' ' << y * (c / v) << '\n';
        else
            g << 0 << ' ' << 0 << '\n';
    }
    f.close();
    g.close();
    return 0;
}