Pagini recente » Cod sursa (job #1792732) | Cod sursa (job #1854397) | Cod sursa (job #1821040) | Cod sursa (job #2009204) | Cod sursa (job #1784745)
#include<fstream>
using namespace std;
ifstream in("inversmodular.in");
ofstream out("inversmodular.out");
void euclid_ext(int a, int b, int &x, int &y)
{
if (b != 0)
{
int x0, y0;
euclid_ext(b, a%b, x0, y0);
x = y0;
y = x0 - y0*(a / b);
}
else
{
x = 1, y = 0;
}
}
int main()
{
int a, N;
in >> a >> N;
int x, y;
euclid_ext(a, N, x, y);
while (x < 0)
x += N;
out << x;
return 0;
}