Pagini recente » Cod sursa (job #2670403) | Istoria paginii utilizator/silentsword | Cod sursa (job #1251320) | Cod sursa (job #450010) | Cod sursa (job #2120765)
#include <iostream>
#include <fstream>
#define LL long long
using namespace std;
/*LL n, a;
LL put(LL a, LL num)
{
if(num == 0)
return 1;
else
{
LL aux = put(a, num / 2) % n;
if(num % 2 == 0)
return (aux % n* aux % n) % n;
return ((aux % n * aux % n) % n) * a % n;
}
}
LL phi(LL nr)
{
LL num = nr;
for(LL i = 2; i * i <= nr; ++i)
{
if (nr % i == 0)
{
while(nr % i == 0)
nr /= i;
num -= (num / i);
}
}
if (nr != 1)
num -= num / nr;
return num;
}
LL inv_mod(int val_a, int val_b)
{
return put(val_a, phi(val_b) - 1) % n;
}*/
inline int gcd( int A, int B, int &X, int &Y )
{
if (B == 0)
{
X = 1;
Y = 0;
return A;
}
int X0, Y0, D;
D = gcd( B, A % B, X0, Y0 );
X = Y0;
Y = X0 - (A / B) * Y0;
return D;
}
int main()
{
int n, a, b, d, x, y, c;
ifstream f("euclid3.in");
ofstream g("euclid3.out");
f >> n;
for(int i = 0; i < n; ++i)
{
f >> a >> b >> c;
d = gcd( a, b, x, y );
cout << x << " " << y << '\n';
if(c % d)
g << "0 0\n";
else
g << x * c / d << " " << y * c / d << '\n';
}
}