Modular multiplicative inverse
알고리즘 2015. 8. 21. 10:45 |references :
https://en.wikipedia.org/wiki/Modular_multiplicative_inverse
In modular arithmetic, the modular multiplicative inverse of an integer a modulo m is an integer x such that
That is, it is the multiplicative inverse in the ring of integers modulo m, denoted .
Once defined, x may be noted , where the fact that the inversion is m-modular is implicit.
The multiplicative inverse of a modulo m exists if and only if a and m are coprime (i.e., if gcd(a, m) = 1).[1] If the modular multiplicative inverse of a modulo m exists, the operation of divisionby a modulo m can be defined as multiplying by the inverse, which is in essence the same concept as division in the field of reals.
[wiki]
example :
http://codeforces.com/contest/560/problem/E
test code :
are each number of factorial series and 10e9+7 coprime ?
extended Euclidean algorithm
The modular multiplicative inverse of a modulo m can be found with the extended Euclidean algorithm.
The algorithm finds solutions to Bézout's identity
한국어: https://medium.com/@jongukim/extended-euclidean-algorithm-8101bafb9164
test codes: