Pagini recente » Cod sursa (job #219361) | Cod sursa (job #732108) | Cod sursa (job #188904) | Cod sursa (job #659603) | Cod sursa (job #1499800)
#include <cstdio>
#define LL long long
using namespace std;
int a, mod;
LL inv = 0, ins;
void cmmdc(LL &x, LL &y, int a, int b)
{
if (!b)
x = 1, y = 0;
else
{
cmmdc(x, y, b, a % b);
LL aux = x;
x = y;
y = aux - y * (a / b);
}
}
int main()
{
freopen("inversmodular.in", "r", stdin);
freopen("inversmodular.out", "w", stdout);
scanf("%d %d", &a, &mod);
cmmdc(inv, ins, a, mod);
if (inv <= 0)
inv = mod + inv % mod;
printf("%lld\n", inv);
return 0;
}