Pagini recente » Cod sursa (job #431242) | Cod sursa (job #309630) | Cod sursa (job #782343) | Cod sursa (job #1784045) | Cod sursa (job #756652)
Cod sursa(job #756652)
#include <cstdio>
using namespace std;
long long mod;
void inversModular (long long a, long long n, long long &x, long long &y) {
long long xx, yy;
if (a == 0) {
x = 0;
y = 1;
return;
}
inversModular (n % a, a, xx, yy);
x = (yy - xx * (n / a)) % mod;
y = xx;
if (x < 0) {
x += mod;
}
}
int main () {
long long a, n, x, y;
freopen ("inversmodular.in", "rt", stdin);
freopen ("inversmodular.out", "wt", stdout);
scanf ("%lld%lld", &a, &n);
mod = n;
inversModular (a % n, n, x, y);
printf ("%d\n", x);
return 0;
}