• + 0 comments

    Actually, the euclidean extended algorithm is faster than the fast exponentiation of b^(M-2)%m https://en.wikipedia.org/wiki/Extended_Euclidean_algorithm because b and M are corpime (statted in the problem and M is prime) there exists a bezout identity X*b + Y*M = 1, so in modulo M, the inverse of b is X.