Pagini recente » Cod sursa (job #2404361) | Cod sursa (job #914428) | Cod sursa (job #1051311) | Cod sursa (job #333165) | Cod sursa (job #2756682)
#include <fstream>
using namespace std;
void euclid(long long a, long long b, long long &x, long long &y)
{
if (b == 0)
{
x = 1;
y = 0;
return;
}
long long xx = x, yy = x;
euclid(b, a % b, xx, yy);
y = xx - (a / b) * yy;
x = yy;
}
int main()
{
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
long long a, n, x, y;
fin >> a >> n;
euclid(a, n, x, y);
fout << (x % n + n) % n;
return 0;
}