Pagini recente » Cod sursa (job #2236065) | Cod sursa (job #582637) | Cod sursa (job #1150543) | Cod sursa (job #879197) | Cod sursa (job #1458435)
#include <fstream>
using namespace std;
void ExtendedEuclid(int a, int b, int &d, int &x, int &y)
{
if(!b)
{
d = a;
x = 1;
y = 0;
}
else
{
int x0,y0;
ExtendedEuclid(b,a%b,d,x0,y0);
x = y0;
y = x0 - (a/b) * y0;
}
}
int main()
{
ifstream f("euclid3.in");
ofstream g("euclid3.out");
int t;
f>>t;
while(t--)
{
int a,b,c,d,x,y;
f>>a>>b>>c;
ExtendedEuclid(a,b,d,x,y);
if(c % d == 0)
{
g<<x * (c/d) <<" "<< y * (c/d)<<"\n";
}
else
g<<"0 0\n";
}
return 0;
}