Pagini recente » Cod sursa (job #1240632) | Cod sursa (job #2735144) | Cod sursa (job #2293880) | Cod sursa (job #2755530) | Cod sursa (job #2439289)
#include <fstream>
using namespace std;
ifstream fin ("euclid3.in");
ofstream fout("euclid3.out");
int euclid( int A, int B, int &X, int &Y ){
if (B == 0){
X = 1;
Y = 0;
return A;
}
int X0, Y0, D;
D = euclid( B, A % B, X0, Y0 );
X = Y0;
Y = X0 - (A / B) * Y0;
return D;
}
int main(){
int t, a, b, c, x, y, d;
fin >> t;
while (t){
fin >> a >> b >> c;
d = euclid (a, b, x, y);
if (c%d)
fout << 0 << " " << 0 << '\n';
else fout << x*(c/d) << " " << y*(c/d) << '\n';
t--;
}
fin.close();
fout.close();
return 0;
}