Pagini recente » Borderou de evaluare (job #1535331) | Cod sursa (job #2654981) | Cod sursa (job #310458) | Cod sursa (job #445471) | Cod sursa (job #2606363)
#include <fstream>
using namespace std;
int euclid( int a, int b ){
if( b == 0 ){
return a;
}
return euclid( b, a % b );
}
void euclid_e ( 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_e ( b, a % b, xx, yy, d );
x = yy, y = xx - yy * q;
}
int main() {
ifstream fin( "euclid3.in" );
ofstream fout( "euclid3.out" );
int n, i, a, b, c, x, y, d, cmmdc, a1, b1;
fin >> n;
for ( i = 0; i < n; i++ ){
fin >> a >> b >> c;
a1 = a, b1 = b;
cmmdc = euclid( a1, b1 );
euclid_e( a, b, x, y, d );
if( c % cmmdc != 0 )
fout << "0" << " " << "0" << "\n";
else
fout << c / cmmdc * x << " " << c / cmmdc * y << "\n";
}
return 0;
fin.close();
fout.close();
}