Pagini recente » Cod sursa (job #159197) | Cod sursa (job #1584321) | Cod sursa (job #1187082) | Cod sursa (job #2236220) | Cod sursa (job #982371)
Cod sursa(job #982371)
#include <iostream>
#include <fstream>
using namespace std;
void euclid_extins(int a, int b, int*x , int *y)
{
if (b == 0) {
printf ("intra aici");
printf (" b = 0 ; x = %i, y = %i", *x,*y);
*x = 1; *y = 0;
}
else { printf(" x = %i, y = %i \n", *x, *y);
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();
system("pause");
return 0;
}