Pagini recente » Cod sursa (job #402699) | Cod sursa (job #1543836) | Cod sursa (job #2395108) | Cod sursa (job #2659460) | Cod sursa (job #1327755)
#include<fstream>
#include<iostream>
using namespace std;
int main()
{
ifstream in_file("euclid3.in");
ofstream out_file("euclid3.out");
short equations;
int c, coefficient1, coefficient2, old_coefficient1, old_coefficient2, remainder, old_remainder, quotient, aux;
for (in_file >> equations; equations; --equations)
{
coefficient1 = old_coefficient2 = 0;
coefficient2 = old_coefficient1 = 1;
in_file >> old_remainder >> remainder >> c;
while (remainder)
{
quotient = old_remainder / remainder;
aux = remainder;
remainder = old_remainder - quotient * aux;
old_remainder = aux;
aux = coefficient1;
coefficient1 = old_coefficient1 - quotient * aux;
old_coefficient1 = aux;
aux = coefficient2;
coefficient2 = old_coefficient2 - quotient * aux;
old_coefficient2 = aux;
}
if (c % old_remainder)
out_file << "0 0\n";
else
out_file << c / old_remainder * old_coefficient1 << ' ' << c / old_remainder * old_coefficient2 << '\n';
}
return 0;
}