Pagini recente » Cod sursa (job #2664035) | Cod sursa (job #3226701) | Cod sursa (job #594716) | Cod sursa (job #1457017) | Cod sursa (job #2027956)
//============================================================================
// Name : Algoritm.cpp
// Author :
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <iostream>
#include <fstream>
using namespace std;
ifstream in("euclid3.in");
ofstream out("euclid3.out");
void euclid(long int a, long int b, long int *d, long int *x, long int *y)
{
if (b == 0) {
*d = a;
*x = 1;
*y = 0;
} else {
long int x0, y0;
euclid(b, a % b, d, &x0, &y0);
*x = y0;
*y = x0 - (a / b) * y0;
}
}
int main() {
long int a , b , c , nr , i , *d, *x , *y , m ;
d = new long int ;
x = new long int ;
y = new long int ;
in >> nr ;
for(i=0;i<nr;i++) {
in >> a >> b >> c ;
euclid(a,b,d,x,y);
if(c%*d!=0) out << "0 0";
else
{
m = c / *d;
*x *= m ;
*y *=m ;
*d*=m;
out << *x << " " << *y << '\n' ; }
}
}