Pagini recente » Cod sursa (job #2860794) | Monitorul de evaluare | Cod sursa (job #3183599) | Cod sursa (job #2276060) | Cod sursa (job #1234877)
#include <fstream>
using namespace std;
ifstream inFile("euclid3.in");
ofstream outFile("euclid3.out");
int cmmdc(int a, int b)
{
if( a%b == 0 ) return b;
else return cmmdc(b, a%b);
}
void solve(int a, int b, int &x, int &y)
{
if( b == 0 ){
x = 1; y = 0;
}else{
int x0, y0;
solve(b, a%b, x0, y0);
x = y0;
y = x0 - (a/b)*y0;
}
}
int main()
{
int T;
inFile >> T;
int x, y, x0, y0;
int a, b, c;
while(T--){
inFile >> a >> b >> c;
if( a == 0 && b == 0){
if( c == 0 ) outFile << "1 1\n";
else outFile << "0 0\n";
continue;
}
int aux = cmmdc(a,b);
if( c % aux != 0){
outFile << "0 0\n";
}
else{
solve(a, b, x, y);
outFile << x*(c/aux) << " " << y*(c/aux) << "\n";
}
}
}