Pagini recente » Cod sursa (job #2382558) | Cod sursa (job #1031588) | Cod sursa (job #1823251) | Cod sursa (job #2231368) | Cod sursa (job #732209)
Cod sursa(job #732209)
#include <fstream>
int euclid_extins (int a, int b, int &x, int &y)
{
if (!b)
{
x = 1;
y = 0;
return a;
}
int x0, y0, d(euclid_extins(b,a % b,x0,y0));
x = y0;
y = x0 - (a / b) * y0;
return d;
}
int main (void)
{
std::ifstream input("euclid3.in");
unsigned int n;
input >> n;
std::ofstream output("euclid3.out");
signed int a,b,x,y,c,d,aux;
do
{
input >> a >> b >> c;
d = euclid_extins(a,b,x,y);
if (c % d)
output << "0 0";
else
{
aux = c / d;
output << x * aux << ' ' << y * aux;
}
output << '\n';
--n;
}
while (n);
input.close();
output.close();
return 0;
}