Pagini recente » Cod sursa (job #664815) | Cod sursa (job #1850587) | Cod sursa (job #2763685)
// Algoritmul lui Euclid extins.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include <iostream>
#include <fstream>
#pragma warning(disable:4996)
using namespace std;
FILE* fin, * fout;
int T;
int a, b, c, d, x, y;
void euclid(int a, int b, int& d, int& x, int& y)
{
if (b == 0)
{
d = a;
x = 1, y = 0;
}
else
{
int x0, y0;
euclid(b, a % b, d, x0, y0);
x = y0;
y = x0 - (a / b) * y0;
}
}
void Read()
{
fin = fopen("euclid3.in", "r");
fout = fopen("euclid3.out", "w");
}
void Solve()
{
fscanf(fin, "%d", &T);
for (; T; T--)
{
fscanf(fin, "%d %d %d", &a, &b, &c);
euclid(a, b, d, x, y);
if (c % d == 0)
{
// ax + by = d -> a(nx) + b(ny) = nd = c
fprintf(fout, "%d %d \n", (c / d) * x, (c / d) * y);
}
else
fprintf(fout, "%d %d \n", 0, 0);
}
}
int main()
{
Read();
Solve();
return 0;
}