Modular Inverse — Solution & Editorial
By Fermat's little theorem, Ap−2 is the inverse modulo a prime p; compute it with fast exponentiation (extended Euclid also works).
Complexity: O(log p)
By Fermat's little theorem, Ap−2 is the inverse modulo a prime p; compute it with fast exponentiation (extended Euclid also works).
Complexity: O(log p)