Pagini recente » Cod sursa (job #2968178) | Cod sursa (job #1581185) | Cod sursa (job #3123214) | Cod sursa (job #2086776) | Cod sursa (job #756090)
Cod sursa(job #756090)
#include <cstdio>
using namespace std;
long long mod;
void inversModular (long long a, long long n, long long &x, long long &y) {
long long c, xx, yy;
if (a == 0) {
x = 0; y = 1;
return;
}
inversModular (n % a, a, xx, yy);
y = xx % mod;
x = (yy - xx * (n / a)) % mod;
if (y < 0) {
y += mod;
}
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;
for (int i = 0; i < 100000; ++ i)
inversModular (a % n, n, x, y);
printf ("%d\n", x);
return 0;
}