Pagini recente » Cod sursa (job #2433696) | Cod sursa (job #3216136) | Cod sursa (job #1665859) | Cod sursa (job #2722971) | Cod sursa (job #1883277)
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("euclid3.in");
ofstream g("euclid3.out");
int N,A,B,C,D;
int cmmdc(int a,int b)
{
int r = 0;
while( b != 0 )
{
r = a%b;
a = b;
b = r;
}
return a;
}
struct Pair
{
int x,y;
}P;
Pair Euclid(int a,int b,int d)
{
Pair p,po;
if( b == 0 )
{
d = a;
p.x = 1;
p.y = 0;
return p;
}
else
{
po = Euclid( b, a % b, d);
p.x = po.y;
p.y = po.x - (a / b) * po.y;
return p;
}
}
int main()
{
f>>N;
for(int i = 1 ; i <= N ; i++)
{
f>>A>>B>>C;
D = cmmdc(A,B);
if( C % D != 0 )
g<<0<<' '<<0<<'\n';
else
{
P = Euclid(A,B,D);
P.x*=(C/D);
P.y*=(C/D);
g<<P.x<<' '<<P.y<<'\n';
}
}
return 0;
}