Cod sursa(job #2487953)

Utilizator FlorianMarcuMarcu Florian Cristian FlorianMarcu Data 5 noiembrie 2019 21:41:51
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.85 kb
// Euclid extins.cpp : Defines the entry point for the console application.
//

//#include "stdafx.h"
#include <fstream>
std::ifstream fin("euclid3.in");
std::ofstream fout("euclid3.out");

long long max(long long a, long long b) {
	if (a > b)
		return a;
	else return b;
}
void euclid_extins(long long *x, long long *y, long long a, long long b, long long *d)
{
	if (b == 0)
	{
		*x = 1;
		*y = 0;
		*d = a;
	}
	else {
		long long x0, y0;
		euclid_extins(&x0, &y0, b, a%b, d);
		*x = y0;
		*y = x0 - (a / b)* y0;
	}
}

int main()
{
	short T;
	fin >> T;
	long long a, b, c;
	long long x = 0, y = 0;
	for (int i = 0; i < T; i++) {
		fin >> a >> b >> c;
		long long d;
		euclid_extins(&x, &y, a, b, &d);
		if ( c % d == 0 )
			fout << x * c/d << " " << y * c/d << std::endl; 
		else fout << 0 << " " << 0 << std::endl;
				
		}
}