Cod sursa(job #2884185)

Utilizator DooMeDCristian Alexutan DooMeD Data 2 aprilie 2022 15:49:43
Problema Algoritmul lui Euclid extins Scor 60
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.53 kb
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

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

int main() {
	ifstream f("euclid3.in");
	ofstream g("euclid3.out");
	
	int t; f >> t;
	while(t--) {
		ll a, b, c; f >> a >> b >> c;
		ll d, x, y;
		euclid(a, b, d, x, y);
		if(c % d == 0) 
			g << 1LL * c/d * x << " " << 1LL * c/d * y << "\n";
		else g << "0 0\n";
	}
	return 0;
}