Cod sursa(job #2875881)

Utilizator PatrascuAdrian1Patrascu Adrian Octavian PatrascuAdrian1 Data 22 martie 2022 15:32:16
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.09 kb
#include <bits/stdc++.h>

using namespace std;

ifstream in("euclid3.in");
ofstream out("euclid3.out");

using ll = long long;

ll gcd_facut_in_casa(ll a, ll b)
{
    ll c;
    while(b)
    {
        c = b;
        b = a % b;
        a = c;
    }
    return a;
}

void euclid_extins(ll a, ll b, ll *d, ll *x, ll *y)
{
    if(b == 0)
    {
        *d = a;
        *x = 1;
        *y = 0;
    }
    else
    {
        ll x0, y0;
        euclid_extins(b, a % b, d, &x0, &y0);
        *x = y0;
        *y = x0 - (a / b) * y0;
    }
}

int main()
{
    ll T, a, b, c, d;
    in >> T;
    while(T--)
    {
        in >> a >> b >> c;
        //d = __gcd(a,b);
        d = gcd_facut_in_casa(a,b);
        //out << d << '\n';
        if(c % d)
        {
            out << 0 << " " << 0 << '\n';
        }
        else
        {
            ll e, x, y;
            euclid_extins(a, b, &e, &x, &y);
            //out << a << " " << b << " " << e << " " <<x << " " << y << '\n';
            out << x * c / d << " " << y * c / d << '\n';
        }
    }
    return 0;
}