Cod sursa(job #2225035)

Utilizator mihai50000Mihai-Cristian Popescu mihai50000 Data 25 iulie 2018 18:54:48
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.58 kb
#include <bits/stdc++.h>

using namespace std;

//#define IOS ios::sync_with_stdio(false), cin.tie(0);

ifstream fin("euclid3.in");
ofstream fout("euclid3.out");

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

int main() 
{
	int n;
	fin >> n;
	while(n--)
	{
		int a, b, c, x, y, d;
		fin >> a >> b >> c;
		euclid(a, b, x, y, d);
		fout << '\n';
		if(c % d)
			fout << 0 << ' ' << 0;
		else
			fout << x * (c / d) << ' ' << y * (c / d);
		fout << '\n';
	}
}