Pagini recente » Cod sursa (job #3207412) | Cod sursa (job #2042780) | Cod sursa (job #2399701) | Cod sursa (job #1281807) | Cod sursa (job #1892612)
#include<fstream>
using namespace std;
ifstream f("euclid3.in");
ofstream g("euclid3.out");
void readTestCase(int &a, int &b, int &c) {
//
f >> a >> b >> c;
return;
}
void computeFactors(int a, int b, int &gcd, int &x, int &y) {
//
if (b == 0) {
gcd = a;
x = 1;
y = 0;
}
else {
computeFactors(b, a % b, gcd, x, y);
int aux = x;
x = y;
y = aux - (a / b) * y;
}
}
void solveTestCase(int a, int b, int c, int &x, int &y) {
//
int gcd;
computeFactors(a, b, gcd, x, y);
if (c % gcd != 0) {
x = y = 0;
return;
}
else {
int multiplier = c / gcd;
x = x * multiplier;
y = y * multiplier;
}
return;
}
int main() {
//
int tc;
int a, b, c, x = 0, y = 0;
f >> tc;
while (tc) {
//
readTestCase(a, b, c);
solveTestCase(a, b, c, x, y);
g << x << " " << y << "\n";
tc--;
}
return 0;
}