Pagini recente » Cod sursa (job #192701) | Cod sursa (job #260196) | Cod sursa (job #2525301) | Cod sursa (job #1008309) | Cod sursa (job #602424)
Cod sursa(job #602424)
#include <fstream>
#include <cstring>
using namespace std;
ifstream in;
ofstream out;
inline int cmmdc(int a,int b)
{
if(b) return cmmdc(b,a%b);
else return a;
}
inline void euclid(int a,int b,int &x,int &y)
{
if(!b)
{
x=1;
y=0;
}
else
{
int x0,y0;
euclid(b,a%b,x0,y0);
x=y0;
y=x0-(a/b)*y0;
}
}
int main()
{
int T,a,b,c,d,x,y;
in.open("euclid3.in");
out.open("euclid3.out");
in>>T;
for(;T;--T)
{
in>>a>>b>>c;
d=cmmdc(a,b);
if(c%d) out<<"0 0\n";
else
{
euclid(a,b,x,y);
out<<x*(c/d)<<' '<<y*(c/d)<<'\n';
}
}
in.close();
out.close();
return 0;
}