Pagini recente » Cod sursa (job #1633924) | Cod sursa (job #631783) | Cod sursa (job #2677769) | Cod sursa (job #1420188) | Cod sursa (job #1253747)
#include <iostream>
#include <fstream>
using namespace std;
typedef long long ll;
int extgcd(int a, int b, int &x, int &y)
{
if (b == 0) {
x = 1;
y = 0;
return a;
}
int x0, y0, d;
d = extgcd(b, a % b, x0, y0);
x = y0;
y = x0 - (a/b)*y0;
return d;
}
int main()
{
ifstream f ("euclid3.in");
ofstream g ("euclid3.out");
int T, a, b, c;
f >> T;
while(T--) {
f >> a >> b >> c;
int d, x, y;
d = extgcd(a,b,x,y);
if (c % d != 0) {
g << 0 << ' ' << 0 << '\n';
} else {
g << x * (c / d) << ' ' << y * (c / d) << '\n';
}
}
return 0;
}