Pagini recente » Cod sursa (job #254112) | Cod sursa (job #405814) | Cod sursa (job #1435588) | Cod sursa (job #1418971) | Cod sursa (job #533084)
Cod sursa(job #533084)
#include <algorithm>
#include <fstream>
using namespace std;
const char Input[] = "euclid3.in";
const char Output[] = "euclid3.out";
int T;
void EucEx( int a, int b, int &d, int &x, int &y ) {
int x0, y0;
if( b == 0 ) {
d = a;
x = 1;
y = 0;
}
else {
EucEx( b, a % b, d, x0, y0 );
x = y0;
y = x0 - (a / b) * y0;
}
}
int main() {
ifstream fin( Input );
ofstream fout( Output );
int a, b, c, d, x, y;
fin >> T;
while( T-- ) {
fin >> a >> b >> c;
EucEx( a, b, d, x, y );
if( c % d )
fout << "0 0\n";
else
fout << x * c / d << " " << y * c / d << "\n";
}
fin.close();
fout.close();
return 0;
}