Modular inverse modulo prime
Your task
Given an integer a and a prime p with a not divisible by p, return the modular multiplicative inverse of a modulo p (the unique value x in [0, p) with a*x = 1 mod p). Constraints: 1 <= a < 1e18, 2 <= p <= 1e9+7 and p is prime, gcd(a, p) = 1.
Examples
mod_inverse(a: int, p: int) -> intExample 1
Input
mod_inverse(3, 7)Output
5