Pagini recente » Cod sursa (job #1627844) | Cod sursa (job #1708132) | Cod sursa (job #1674591) | Cod sursa (job #1045533) | Cod sursa (job #1972102)
#include <iostream>
#include <fstream>
using namespace std;
ifstream in("inversmodular.in");
ofstream out("inversmodular.out");
int A, N;
void euclid (int a, int b, long long &x, long long &y)
{
if (b == 0)
{
x = 1;
y = 0;
}
else
{
euclid (b, a % b, x, y);
long long aux = x;
x = y;
y = aux - (a / b) * y;
}
}
int main()
{
long long inv = 0, ins;
in >> A >> N;
euclid (A, N, inv, ins);
if (inv <= 0)
inv = N + inv % N;
out << inv;
return 0;
}