乘法逆元

Multiplicative Inverse.

Definition. If for a given integer bb, there exists an integer cc such that bc=1mod  Nbc=1\mod{N}, we say that bb is invertible modulo NN, and call cc a multiplicative inverse of bb modulo NN.

The multiplicative inverse is NOT unique. For an invertible bb, if cc is an inverse of bb, every xx congruent with cc modulo NN is also an inverse of bb. (x≡cmod  Nx\equiv c\mod{N}). We use b−1b^{-1} to denote the inverse of bb that b−1∈{1,2,...N−1}b^{-1}\in\{1,2,...N-1\}.

Theorem. Let b,Nb,N be integers, with b≥1b\geq 1, and N>1N>1. Then bb is invertible modulo NN if and only if bb is relatively prime to NN. Note that integers b,Nb,N are relatively prime (or coprime) means gcd⁡(b,N)=1\gcd(b,N)=1.

Therefore, for a prime pp, every b∈{1,2,...p−1}b\in \{1,2,...p-1\} is invertible modulo pp.

The above theorem could be proved by applying **Bezout's identity: ** it states that for every positive integer a,ba,b, there exists a pair of integers ⟨X,Y⟩\langle X,Y \rangle that Xa+Yb=gcd⁡(a,b)Xa+Yb=\gcd(a,b).

Eureka moment!

逆元这个概念算是老熟人了;它将模意义下的除法转化为乘法。

求逆元的常见方法:扩展欧几里得算法,欧拉定理,费马小定理。这些方法在接下来都会进行介绍。