Loading repovive.com/problems/classics/25
Given integers a and m (where m is a prime number), find the modular multiplicative inverse of a modulo m.
The modular inverse of a modulo m is an integer x such that: a⋅x≡1(modm)
When m is prime and a is not divisible by m, use Fermat's Little Theorem: a−1≡am−2(modm)
am
a−1modm
3 7
For this input, the required output is 5.
5
2 5
For this input, the required output is 3.
3
4 11
For this input, the required output is 3.
3