Cod sursa(job #1528096)

Utilizator whoiscrisCristian Plop whoiscris Data 19 noiembrie 2015 01:15:11
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.62 kb
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;

typedef long long int ll;

#define REP(i, a, b) \
	for (int i=int(a); i<=int(b); ++i)

ifstream f("euclid3.in");
ofstream g("euclid3.out");

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


ll a, b, c, x, y, d;

int main () {

	int t;
	f >> t;
	while (t--) {
		f >> a >> b >> c;
		egcd(a, b, &d, &x, &y);
		if (c % d)
			x = y = 0;
		else {
			x *= (c/d);
			y *= (c/d);
		}
		g << x << " " << y << endl;
	}

	return 0;
}