Pagini recente » Cod sursa (job #1643936) | Cod sursa (job #2716567) | Cod sursa (job #2309162) | Cod sursa (job #1553197) | Cod sursa (job #2924279)
#include <fstream>
using namespace std;
ifstream fin("euclid3.in");
ofstream fout("euclid3.out");
void euclid(int a, int b, int &d, int &x, int &y);
int main()
{
int n, x, y, d, d1, a, b;
fin>>n;
for (int i = 0; i < n; i++)
{
fin>>a>>b>>d;
d1 = d;
euclid(a, b, d, x, y);
if (d1 % d == 0)
fout<<x*(d1/d)<<" "<<y*(d1/d);
else
fout<<"0 0";
fout<<"\n";
}
fin.close();
fout.close();
return 0;
}
void euclid(int a, int b, int &d, int &x, int &y)
{
if (b == 0)
{
x = 1;
y = 0;
d = a;
}
else
{
int x1, y1;
euclid(b, a % b, d, x1, y1);
x = y1;
y = x1 - y1 * (a / b);
}
}