Cod sursa(job #2290476)

Utilizator MaarcellKurt Godel Maarcell Data 26 noiembrie 2018 16:07:04
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.49 kb
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <cstring>
#include <ctime>
#include <unordered_map>
#include <iomanip>
#include <complex>
#include <cassert>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define deb(a) cerr<< #a << "= " << (a)<<"\n";

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef long double ld;
typedef complex<double> base;
typedef vector<int> vi;
typedef pair<int,int> pii;

template<class T> ostream& operator<<(ostream& stream, const vector<T> v){ stream << "[ "; for (int i=0; i<(int)v.size(); i++) stream << v[i] << " "; stream << "]"; return stream; }
ll fpow(ll x, ll p, ll m){ll r=1; for (;p;p>>=1){ if (p&1) r=r*x%m; x=x*x%m; } return r;}
ll inv(ll a, ll b){ return a<2 ? a : ((a-inv(b%a,a))*b+1)/a%b; }
int gcd(int a, int b){ if (!b) return a; return gcd(b,a%b);}
ll gcd(ll a, ll b){ if (!b) return a; return gcd(b,a%b);}


int T; ll a,b,c;

void ext(ll a, ll b, ll c, ll &x, ll &y){
	if (!b){
		x=c/a;
		y=0;
		return;
	}
	
	ll nx,ny;
	ext(b,a%b,c,nx,ny);
	x=ny,y=nx-(a/b)*ny;
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	ifstream cin("euclid3.in");
	ofstream cout("euclid3.out");
	cin >> T;
	
	while (T--){
		cin >> a >> b >> c;
		
		ll gd=gcd(a,b);
		if (c%gd!=0){
			cout << "0 0\n";
			continue;
		}
		
		ll x,y;
		ext(a,b,c,x,y);
		cout << x << " " << y << "\n";
	}
}