We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
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.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Simple One
You are viewing a single comment's thread. Return to all 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.