Pagini recente » Cod sursa (job #524803) | Cod sursa (job #231037) | Cod sursa (job #792073) | Cod sursa (job #2083273) | Cod sursa (job #1546172)
#include <iostream>
#include <fstream>
using namespace std;
void euclid(int a, int b, int &d, int &x, int &y)
{
if (b == 0)
{
x = 1;
y = 0;
d = a;
}
else
{
int x0,y0;
euclid(b, a % b,d,x0,y0);
x = y0;
y = x0 - (a / b) * y0;
}
}
int main()
{
fstream f,g;
f.open("euclid3.in",ios::in);
g.open("euclid3.out",ios::out);
int a,b,c,t,x,y,d,i;
f>>t;
for(i=1;i<=t;i++)
{
x=0;
y=0;
f>>a>>b>>c;
euclid(a,b,d,x,y);
if(c%d!=0) g<<"0 0"<<endl;
else
g<<x*(c/d)<<" "<<y*(c/d)<<'\n';
}
}