Pagini recente » Cod sursa (job #257363) | Cod sursa (job #245773) | Cod sursa (job #3186061) | Cod sursa (job #1508563) | Cod sursa (job #606606)
Cod sursa(job #606606)
#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 >> d;
euclid (a,b,d,x,y);
g << x << ' ' << y << '\n';
}
f.close();g.close();
return 0;
}