Cod sursa(job #2587568)
| Utilizator | Data | 23 martie 2020 00:13:36 | |
|---|---|---|---|
| Problema | Algoritmul lui Euclid extins | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.68 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream fin ("euclid3.in");
ofstream fout ("euclid3.out");
void euclid (int a, int b, int& x, int& y, int& D)
{
if (!b)
{
D = a;
x = 1;
y = 0;
}
else
{
int x0, y0;
euclid (b, a % b, x0, y0, D);
x = y0;
y = (x0 - y0 * (a / b));
}
}
int main ()
{
int t, a, b, c, x, y, D;
fin >> t;
while (t)
{
fin >> a >> b >> c;
euclid (a, b, x, y, D);
if (c % D)
fout << 0 << " " << 0;
else
fout << x * (c / D) << " " << y * (c / D);
fout << "\n";
t--;
}
}
