Pagini recente » Cod sursa (job #3289504) | Cod sursa (job #2627657) | Cod sursa (job #3279526) | Cod sursa (job #2232778) | Cod sursa (job #1115811)
//#include "stdafx.h"
//references
//http://www.infoarena.ro/algoritmul-lui-euclid
#include <fstream>
#include <iostream>
std::ifstream in("euclid3.in");
std::ofstream out("euclid3.out");
void euclid(long a, long b, long c, long* x, long *y)
{
if (b==0)
{
*x = 1;
*y = 0;
}
else
{
long x0, y0;
euclid(b, a % b, c, &x0, &y0);
*x = y0;
*y = x0 = (a/b) * y0;
}
}
int main()
{
int T;
in >> T;
for (int i = 0; i < T; i++)
{
long a,b,c;
in >> a >> b >> c;
long x, y = 0;
euclid(a,b,c, &x, &y);
out << x << " " << y;
}
}