Pagini recente » Cod sursa (job #3140766) | Cod sursa (job #255512) | Cod sursa (job #1607792) | Cod sursa (job #2990186) | Cod sursa (job #675842)
Cod sursa(job #675842)
#include<fstream>
using namespace std;
int n;
void euclid_extins(int a, int b, int d, int &x, int &y, int &cmmdc)
{
int x2,y2;
if (d == -1)
{
d = a / b;
euclid_extins(a,b,d,x2,y2,cmmdc);
x = y2;
y = x2 - y2 * d;
} else
{
swap(a, b);
b = b % a;
d = a / b;
if (a % b)
{
euclid_extins(a,b,d,x2,y2,cmmdc);
x = y2;
y = x2 - y2 * d;
} else
{
x = 0;
y = 1;
cmmdc = b;
}
}
}
void read_solve()
{
int i,a,b,c,x,y,cmmdc;
ifstream fin("euclid3.in");
ofstream fout("euclid3.out");
fin>>n;
for (i=1; i<=n; ++i)
{
fin>>a>>b>>c;
euclid_extins(a, b, -1, x, y, cmmdc);
if (c % cmmdc == 0)
{
x *= c / cmmdc;
y *= c / cmmdc;
fout<<x<<" "<<y<<'\n';
} else
fout<<"0 0"<<'\n';
}
fin.close();
fout.close();
}
int main()
{
read_solve();
return 0;
}