Cod sursa(job #3004058)

Utilizator stefantagaTaga Stefan stefantaga Data 16 martie 2023 09:19:04
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.75 kb
#include <bits/stdc++.h>

using namespace std;
ifstream f("euclid3.in");
ofstream g("euclid3.out");
typedef long long ll;
long long a,b,c;
void euclidExtins(ll a,ll b,ll &x,ll &y)
{
    if (b==0)
    {
        x=1;
        y=0;
        return;
    }
    long long c = a/b;
    long long x2,y2;
    euclidExtins(b,a%b,x2,y2);
    x = y2;
    y = x2-c*y2;
}
ll t,gcd;
pair <ll,ll> hello;
int main()
{
    f>>t;
    for (;t--;)
    {
        f>>a>>b>>c;
        gcd = __gcd(a,b);
        if (c%gcd!=0)
        {
            g<<"0"<<" "<<"0"<<'\n';
        }
        else
        {
            long long x,y;
            euclidExtins(a,b,x,y);
            g<<x*(c/gcd)<<" "<<y*(c/gcd)<<'\n';
        }
    }
    return 0;
}