Pagini recente » Cod sursa (job #97948) | Cod sursa (job #1791551) | Cod sursa (job #609982) | Istoria paginii runda/simulare_oji_2021_cl10 | Cod sursa (job #2910344)
#include <iostream>
#include <fstream>
#include <cmath>
using namespace std;
ifstream fin("euclid3.in");
ofstream fout("euclid3.out");
int eucl_ext(int a, int n, long long &x, long long &y)
{
if (n == 0)
{
x = 1;
y = 0;
}
else
{
long long d = eucl_ext(n, a % n, x, y);
long long temp = y;
y = x - y * (a / n);
x = temp;
}
return d;
}
int main()
{
int a, n;
long long x, y;
fin >> a >> n;
eucl_ext(a, n, x, y);
fout << x << ' ' << y;
}