Pagini recente » Cod sursa (job #869198) | Cod sursa (job #2629837) | Cod sursa (job #1047430) | Cod sursa (job #2152063) | Cod sursa (job #2462927)
#include<fstream>
#include<algorithm>
#include<string.h>
#include<string>
#include<math.h>
#include<iostream>
#include<queue>
#include<bitset>
#include<set>
#include<map>
using namespace std;
ifstream in("euclid3.in");
ofstream out("euclid3.out");
int gcd(int x, int y)
{
int r;
while (y != 0)
{
r = x % y;
x = y;
y = r;
}
return x;
}
void euclid_ext(int a, int b, int &x, int &y)
{
int r = a % b;
if (r != 0)
{
int x0, y0;
euclid_ext(b, a%b, x0, y0);
x = y0;
y =x0 - (a/b)*y0;
}
else
{
x = 0;
y = 1;
return;
}
}
int main()
{
int n;
in >> n;
for (int i = 1; i <= n; ++i)
{
int a, b, c;
in >> a >> b >> c;
int g = gcd(a, b);
if (a == 0 || b == 0)
{
if (a == 0 && b == 0)
cout << "0 0\n";
else if (a == 0)
{
if (c%b == 0)
{
cout << "1 " << c / b << "\n";
}
else
cout << "0 0\n";
}
else
{
if (c%a == 0)
{
cout << c/a << " " << 1 << "\n";
}
else
cout << "0 0\n";
}
continue;
}
if (c % g != 0)
{
out << "0 0\n";
}
else
{
int x0, y0;
euclid_ext(a, b, x0, y0);
out << x0 * (c/g) << " " << y0*(c/g) << "\n";
}
}
return 0;
}