multiplicativeInverseOfPrime function

int multiplicativeInverseOfPrime(
  1. int x,
  2. int n
)

Returns the multiplicative inverse of x mod n, where n is a prime.

Implementation

int multiplicativeInverseOfPrime(int x, int n) {
  return expMod(x, n - 2, n);
}