Pagini recente » Cod sursa (job #2872025) | Cod sursa (job #2714914) | Cod sursa (job #2983448) | Cod sursa (job #194872) | Cod sursa (job #1226768)
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("euclid3.in");
ofstream g("euclid3.out");
int a1,a2,b1,b2;
int xGood,yGood;
int euclid(int a ,int b)
{
a1=1,b1=0,a2=0,b2=1;
while (a&&b)
{
if (a>b)
{
a-=b;
a1-=a2;
b1-=b2;
}else
{
b-=a;
b2-=b1;
a2-=a1;
}
}
if (a) xGood=a1,yGood=b1;
else xGood=a2,yGood=b2;
if (a) return a;
else return b;
}
int main()
{
int nrt,tt;
f>>nrt;
for(tt=1; tt<=nrt; ++tt)
{
int xx,yy,cc;
f>>xx>>yy>>cc;
int CMMDC=euclid(xx,yy);
if (cc%CMMDC==0)
{
g<<xGood*(cc/CMMDC)<<" "<<yGood*(cc/CMMDC)<<'\n';
}
else
g<<0<<" "<<0<<'\n';
}
return 0;
}