Pagini recente » Cod sursa (job #2784540) | Cod sursa (job #1565587) | Diferente pentru preoni-2008/runda-1/solutii intre reviziile 29 si 30 | Istoria paginii utilizator/oanantonia | Cod sursa (job #2120764)
#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;
}*/
void euclid(int a, int b, int *d, int *x, int *y)
{
if(b == 0)
{
*d = a;
*x = 1;
*y = 0;
}
else
{
int x0, y0;
euclid(b, a % b, d, &x0, &y0);
*x = y0;
*y = x0 - a / b * y0;
}
}
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;
euclid(a, b, &d, &x, &y);
cout << x << " " << y << '\n';
if(c % d)
g << "0 0\n";
else
g << x * c / d << " " << y * c / d << '\n';
}
}