Cod sursa(job #2566524)

Utilizator CriviCriveanu Bogdan Crivi Data 2 martie 2020 21:47:06
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.61 kb
#include <bits/stdc++.h>

using namespace std;

ifstream in;
ofstream out;

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

int n, p;

int main() {

	in.open("euclid3.in");
	out.open("euclid3.out");

	in >> n;
	for (int i = 1; i <= n; i++)
	{
		int d, x, y, c,a,b;
		in >> a >> b >> c;
		euclid(a, b, d, x, y);
		if (c % d)
			out << 0 << " " << 0 << "\n";
		else
			out << (x * (c / d)) << " " << (y * (c / d)) << "\n";
		
	}

	return 0;
}