Pagini recente » Cod sursa (job #2737561) | Cod sursa (job #2618285) | Cod sursa (job #1845318) | Cod sursa (job #2225059) | Cod sursa (job #606623)
Cod sursa(job #606623)
#include <fstream>
using namespace std;
ifstream f("euclid3.in");
ofstream g("euclid3.out");
int t,ti;
long long a,b,c,d,x,y;
// a*x+b*y=d
void euclid (long long a,long long b,long long &d,long long &x,long long &y) {
if (b==0) {
d=a;
x=1;
y=0;
}
else {
long long x0,y0;
euclid(b, a % b, d, x0, y0);
x=y0;
y=x0 - (a / b) * y0;
}
}
int main() {
f >> t;
for (ti=1;ti<=t;ti++) {
f >> a >> b >> c;d=x=y=0;
euclid (a,b,d,x,y);
if (c%d==0)
g << x*(c/d) << ' ' << y*(c/d) << '\n';
else
g << 0 << ' ' << 0 << '\n';
}
f.close();g.close();
return 0;
}