Pagini recente » Cod sursa (job #339295) | Cod sursa (job #2884924) | Cod sursa (job #2374305) | Cod sursa (job #1711560) | Cod sursa (job #1098904)
#include <fstream>
using namespace std;
ifstream fin("euclid3.in");
ofstream fout("euclid3.out");
long long a, b, c, x, y, t;
void Euclid(long long, long long, long long&, long long&);
long long cmmdc(long long, long long);
int main(){
long long i, d;
fin>>t;
for(i=1; i<=t; i++){
fin>>a>>b>>c;
d=cmmdc(a, b);
if(c%d!=0){
fout<<"0 0"<<'\n';
continue;
}
Euclid(a, b, x, y);
fout<<x*c/d<<' '<<y*c/d<<'\n';
}
fout.close();
return 0;
}
void Euclid(long long a, long long b, long long &x, long long &y){
long long x0, y0;
if(!b) {x=1; y=0; return;}
else Euclid(b, a%b, x0, y0);
x=y0;
y=x0-y0*(a/b);
}
long long cmmdc(long long a, long long b){
if(!b) return a;
return cmmdc(b, a%b);
}