Pagini recente » Cod sursa (job #115604) | Cod sursa (job #3286358) | Cod sursa (job #2179155) | Cod sursa (job #1922850) | Cod sursa (job #3237850)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ifstream fin( "euclid3.in" );
ofstream fout( "euclid3.out" );
int euclid( int a, int b ) {
if ( b == 0 ) return a;
return euclid(b, a % b);
}
void euclid_ext( int a, int b, int &x, int &y ) {
if ( b == 0 ) {
x = 1, y = 0;
return;
}
int px, py;
euclid_ext(b, a % b, px, py);
x = py;
y = px - (a / b) * py;
}
int main() {
ios_base::sync_with_stdio(0);
fin.tie(0);
int t, a, b, c;
fin >> t;
while ( t-- ) {
fin >> a >> b >> c;
int d = euclid(a, b), x, y;
if ( c % d ) {
fout << "0 0\n";
} else {
euclid_ext(a, b, x, y);
fout << c / d * x << " " << c / d * y << "\n";
}
}
fin.close();
fout.close();
return 0;
}