Cod sursa(job #3001424)

Utilizator BadHero112Ursu Vasile BadHero112 Data 13 martie 2023 17:11:55
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.8 kb
#include <bits/stdc++.h>
using ll=long long;
#define S second
#define F first
#define endl '\n'
#define spid ios_base::sync_with_stdio(false);cin.tie(NULL);
const int mod=1e9+7;
const double pi=3.14159265359;
const int maxn=200001;
using namespace std;

ll t=1,a,b,c;

int gcd(ll a,ll b){
	if(b==0)return a;
	return gcd(b,a%b);
}

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

int main(){
	ifstream cin("euclid3.in");
	ofstream cout("euclid3.out");
	cin>>t;
	while(t--){
		cin>>a>>b>>c;
		ll d=gcd(a,b);
		if(c%d!=0){
			cout<<"0 0"<<endl;
			continue;
		}
		a=a;
		b=b;
		
		ll x;
		ll y;
		euclid(a,b,&d,&x,&y);
		cout<<x*c/d<<" "<<y*c/d<<endl;
	}
}