Pagini recente » Cod sursa (job #918360) | Cod sursa (job #454123) | Cod sursa (job #600958) | Cod sursa (job #1325137) | Cod sursa (job #982372)
Cod sursa(job #982372)
#include <iostream>
#include <fstream>
using namespace std;
void euclid_extins(int a, int b, int*x , int *y)
{
if (b == 0) {
*x = 1; *y = 0;
}
else {
euclid_extins ( b, a%b, x , y);
int z = *y, t = *x;
*x = z;
*y = t - (a/b) * z;
}
}
void euclid ( int a,int b,int *d )
{
if ( b == 0 ) {
*d = a;
}
else euclid ( b , a%b, d);
}
int main()
{
ifstream in("euclid3.in");
ofstream out("euclid3.out");
int n;
in >> n;
int a,b,c,i,d=0,x,y;
for (i=0; i < n; i++)
{
in >> a >> b >> c;
euclid ( a,b,&d);
if ( c % d == 0) {
x=0;y=0;
euclid_extins(a,b,&x,&y);
x = c/d * x;
y = c/d * y;
out << x << " " << y << "\n";
}
else out << "0 0\n";
}
in.close();
out.close();
return 0;
}