Cod sursa(job #3328562)

Utilizator tudorhTudor Horobeanu tudorh Data 9 decembrie 2025 11:59:31
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.68 kb
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define pii pair<int,int>
using namespace std;
ifstream fin("euclid3.in");
ofstream fout("euclid3.out");
void euclid(ll a,ll b,ll &x,ll &y,ll &d){
    if(b==0){
        x=1;
        d=a;
        y=0;
    }
    else{
        ll x0=0,y0=0;
        euclid(b,a%b,x0,y0,d);
        x=y0;
        y=x0-a/b*y0;
    }
}
int main()
{
    ll t,st,dr,l,x,y,d;
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    fin>>t;
    while(t--){
        fin>>st>>dr>>l;
        euclid(st,dr,x,y,d);
        if(l%d)
            fout<<"0 0\n";
        else fout<<x*l/d<<' '<<y*l/d<<'\n';
    }
    return 0;
}