Pagini recente » Cod sursa (job #1026112) | Cod sursa (job #1296818) | Istoria paginii runda/td1/clasament | Istoria paginii runda/sim_oji | Cod sursa (job #1990493)
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <ctime>
#include <algorithm>
using namespace std;
ifstream in("euclid3.in");
ofstream out("euclid3.out");
#define ll long long
#define pb push_back
const int inf = 1e9 + 5;
const int NMax = 5e5 + 5;
ll euclid(ll,ll,ll&,ll&);
int main() {
ll T;
in>>T;
while (T--) {
ll a,b,c,x,y;
bool negA = false,negB = false;
in>>a>>b>>c;
if (a < 0) {
negA = true;
a = -a;
}
if (b < 0) {
negB = true;
b = -b;
}
ll d = euclid(a,b,x,y);
if (negA) {
x = -x;
}
if (negB) {
y = -y;
}
//cout<<d<<'\n';
if (c % d) {
out<<"0 0\n";
}
else {
out<<x * (c/d)<<' '<<y * (c/d)<<'\n';
}
}
in.close();out.close();
return 0;
}
ll euclid(ll a,ll b,ll& x,ll& y) {
if (b == 0) {
x = 1;
y = 0;
return a;
}
ll x0,y0,d;
d = euclid(b,a%b,x0,y0);
x = y0;
y = x0 - (a/b)*y0;
return d;
}