Pagini recente » Cod sursa (job #276493) | Cod sursa (job #1844576) | Cod sursa (job #27014) | Cod sursa (job #2862394) | Cod sursa (job #2764770)
#include <bits/stdc++.h>
using namespace std;
ifstream f("euclid3.in");
ofstream g("euclid3.out");
//ifstream f("prieteni.in");
//ofstream g("prieteni.out");
int gcd(int a, int b, int &x, int &y) {
if (b==0) {
x = 1;
y = 0;
return a;
}
int x0, y0, d;
d = gcd(b, a%b, x0, y0);
x = y0;
y = x0 - (a/b)*y0;
return d;
}
int main(){
int n, a, b, c, x, y;
f>>n;
for (int i=0; i<n; i++) {
f>>a>>b>>c;
int d = gcd(a, b, x, y);
if (c % d != 0)
g<<"0 0\n";
else
g<<(c/d)*x<<' '<<(c/d)*y<<'\n';
}
return 0;
}