Cod sursa(job #3344120)

Utilizator tudorhTudor Horobeanu tudorh Data 1 martie 2026 13:45:25
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.71 kb
#include <bits/stdc++.h>
#define ll long long
#define pb push_back

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){
        x=1;
        y=0;
        d=a;
    }
    else{
        ll x0,y0;
        euclid(b,a%b,x0,y0,d);
        x=y0;
        y=x0-a/b*y0;
    }
}



void solve(){
    ll a,b,c,x,y,d;
    fin>>a>>b>>c;
    euclid(a,b,x,y,d);
    if(c%d==0){
        ll coef=c/d;
        fout<<x*coef<<' '<<y*coef<<'\n';
    }
    else fout<<"0 0\n";
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    fin>>t;
    while(t--)
        solve();
    return 0;
}