Pagini recente » Cod sursa (job #1932750) | Cod sursa (job #336470) | Cod sursa (job #1629516) | Cod sursa (job #2584401) | Cod sursa (job #2637120)
#include <iostream>
#include <fstream>
using namespace std;
/// ax + by = d == cmmdc ( a, b );
void gcd_extins ( int a, int b, int *x, int *y, int *d ) {
if ( b == 0 )
*d = a, *x = 1, *y = 0;
else {
int xx, yy;
gcd_extins ( b, a % b, &xx, &yy, d );
*x = yy;
*y = xx - ( a / b ) * yy;
}
}
ifstream fin ( "euclid3.in" );
ofstream fout ( "euclid3.out" );
int main()
{
int n, a, b, c;
int cmmdc, x, y;
fin >> n;
for ( int i = 1; i <= n; i ++ ) {
fin >> a >> b >> c;
gcd_extins ( a, b, &x, &y, &cmmdc );
if ( c % cmmdc )
fout << 0 << ' ' << 0;
else
fout << x * ( c / cmmdc ) << ' ' << y * ( c / cmmdc );
fout << '\n';
}
return 0;
}