Pagini recente » Cod sursa (job #1154259) | Cod sursa (job #2534579) | Cod sursa (job #7178) | Cod sursa (job #1199540) | Cod sursa (job #2334595)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("euclid3.in");
ofstream fout("euclid3.out");
int test;
int a,b,c;
int d;
int x,y,zt;
int gcd(int a,int b,int &x,int &y);
int main() {
fin>>test;
for (;test;--test){
fin>>a>>b>>c;
d=gcd(a,b,x,y);
zt=c%d;
if (zt){
fout<<"0 0\n";
} else {
zt=c/d;
fout<<x*zt<<" "<<y*zt<<"\n";
}
}
return 0;
}
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;
}