Pagini recente » Cod sursa (job #2075352) | Cod sursa (job #2116537) | Cod sursa (job #1595810) | Cod sursa (job #3275456) | Cod sursa (job #2664180)
#include <fstream>
using namespace std;
void euclid(int a, int b, int *d, int *x, int *y) {
if (b == 0) {
*d = a;
*x = 1;
*y = 0;
} else {
int x0, y0;
euclid(b, a % b, d, &x0, &y0);
*x = y0;
*y = x0 - (a / b) * y0;
}
}
ifstream fin( "euclid3.in" );
ofstream fout( "euclid3.out" );
int main() {
int t, a, b, c, d, x, y;
fin >> t;
while( t-- ) {
fin >> a >> b >> c;
euclid( a, b, &d, &x, &y );
fout << (c % d == 0) * (c / d) * x << ' ' << (c % d == 0) * (c / d) * y << '\n';
}
return 0;
}