Pagini recente » Istoria paginii runda/oji_2014_10 | Cod sursa (job #1119320) | Cod sursa (job #3225296) | Cod sursa (job #233529) | Cod sursa (job #1501891)
#include <iostream>
#include <fstream>
using namespace std;
void gcd (int a, int b, int &d, int &x, int &y) {
if (b == 0) {
x = 1,
y = 0,
d = a;
}
else {
int x0, y0;
gcd (b, a%b, d, x0, y0);
x = y0;
y = x0 - (a/b) * y0;
}
}
int main()
{
ifstream fin ("euclid3.in");
ofstream fout ("euclid3.out");
int n, a, b, c;
fin >> n;
for (int i = 0; i < n; i++) {
fin >> a >> b >> c;
int d, x, y;
gcd (a, b, d, x, y);
if (c % d == 0) {
x *= c / d;
y *= c / d;
fout << x << ' ' << y;
}
else
fout << 0 << ' ' << 0;
fout << "\n";
}
}