PowerMod
PowerMod[a, b, m] gives a^b mod m efficiently.
PowerMod[a, -1, m] finds the modular inverse of a modulo m.
Examples
Compute power modulo:
PowerMod[2, 10, 1000]
(* 24 *)Modular inverse:
PowerMod[3, -1, 7]
(* 5 *)Verify the inverse:
Mod[3 * 5, 7]
(* 1 *)Please visit the official Wolfram Language Reference for more details.