Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int modulo(int n, int p)
- {
- int r = n%p;
- if (((p > 0) && (r < 0)) || ((p < 0) && (r > 0)))
- r += p;
- return r;
- }
- int modInverse(int n, int p) {
- n = modulo(n, p);
- for (int x = 1; x < p; x++) {
- if (modulo(n*x, p) == 1) return x;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement