Pagini recente » Cod sursa (job #887801) | Cod sursa (job #1847015) | Cod sursa (job #1861157) | Cod sursa (job #2011603) | Cod sursa (job #2909519)
#include <stdio.h>
#include <iostream>
#include <fstream>
#include <math.h>
// https://infoarena.ro/problema/euclid3
void euclid_ext(long long int a, long long int b, long long int* d, long long int* x, long long int* y)
{
if (b == 0) {
*d = a;
*x = 1;
*y = 0;
}
else {
long long int x0, y0;
euclid_ext(b, a % b, d, &x0, &y0);
*x = y0;
*y = x0 - (a / b) * y0;
}
}
int main() {
std::ifstream fin("euclid3.in");
std::ofstream fout("euclid3.out");
long long int linii, a, b, c, d, x, y;
fin >> linii;
for (int i = 0; i < linii; i++)
{
x = 0;
y = 0;
d = 0;
fin >> a >> b >> c;
euclid_ext(a, b, &d, &x, &y); // a * X + b * Y = c
if (c % d == 0) {
x = x * c / d;
y = y * c / d;
}
else {
x = 0;
y = 0;
}
fout << x << " " << y << "\n";
}
fin.close();
fout.close();
return 0;
}