Pagini recente » Cod sursa (job #1390531) | Cod sursa (job #321298) | Cod sursa (job #1503364) | Cod sursa (job #870847) | Cod sursa (job #630364)
Cod sursa(job #630364)
#include <fstream>
using namespace std;
int x,y,t,a,b,c,d,k;
int euclid (int a,int b) {
if (!(a%b)) {
x=0;
y=-1;
return b;
}
if (b%(a%b)) {
int rez=euclid (b,a%b);
t=x;
x=-y;
y=a/b*x-t;
return rez;
}
else {
x=1; y=a/b;
return a%b;
}
}
int main () {
ifstream in ("grader_test2.in");
ofstream out ("euclid3.out");
in>>k;
while (k--) {
in>>a>>b>>c;
if (a)
if (b) {
d=euclid (a,b);
if (c%d) {
x=0;
y=0;
}
else {
x*=c/d;
y*=-c/d;
}
}
else {
y=0;
if (c%a) x=0;
else x=c/a;
}
else {
if (b) {
x=0;
if (c%b) y=0;
else y=c/b;
}
else {
x=0;
y=0;
}
}
out<<x<<" "<<y<<"\n";
}
return 0;
}