Pagini recente » Cod sursa (job #2221359) | Cod sursa (job #1782108) | Cod sursa (job #1918713) | Cod sursa (job #1820035) | Cod sursa (job #2606357)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin ( "euclid3.in" );
ofstream fout ( "euclid3.out" );
void euclid_extins( int a, int b, int& x, int& y, int& d ) {
if ( b == 0 ) {
d = a;
x = 1;
y = 0;
return;
}
int xx, yy, q = a / b;
euclid_extins( b, a % b, xx, yy, d );
x = yy;
y = xx - yy * q;
}
int cmmdc( int a, int b ) {
if ( b == 0 )
return a;
return cmmdc( b, a % b );
}
int main() {
int a, b, c, t, i;
fin >> t;
for ( i = 0; i < t; i ++ ) {
fin >> a >> b >> c;
int x, y, d = cmmdc( a, b );
if ( c % d == 0 ) { // exista x si y
cout << "c: " << c << "\t" << "d: " << d << "\n";
euclid_extins( a, b, x, y, d );
x *= c / d;
y *= c / d;
}
else {
x = y = 0;
}
fout << x << " " << y << "\n";
}
return 0;
}