Pagini recente » Cod sursa (job #2429853) | Cod sursa (job #44217) | Cod sursa (job #1202078) | Cod sursa (job #3186836) | Cod sursa (job #2973117)
#include <fstream>
#include <iostream>
using namespace std;
void euclidExtended(long long a, long long b, long long &gcd, long long &x, long long &y) {
if (b == 0) {
gcd = a;
x = 1;
y = 0;
} else {
if (a < b) {
swap(a,b);
}
euclidExtended(b, a % b, gcd, x, y);
long long xNew = y;
long long yNew = x - (a / b) * y;
x = xNew;
y = yNew;
}
}
int main()
{
ifstream fin("euclid3.in");
ofstream fout("euclid3.out");
int test;
fin >> test;
for (int i = 1; i <= test; ++i) {
long long a, b, c, d, x, y;
fin >> a >> b >> c;
euclidExtended(a, b, d, x, y);
if (c % d != 0) {
fout << "0" << " " << "0" << "\n";
} else {
fout << x * c / d << " " << y * c / d << "\n";
}
}
}