📜  在 Z*n 中求逆 - 无论代码示例

📅  最后修改于: 2022-03-11 14:55:45.432000             🧑  作者: Mango

代码示例1
Suppose that gcd(a,m)=1, so that a−1 exists in Zm. One (fairly) efficient way to find the inverse is to use the Euclidean algorithm to find the Bézout coefficients. Recall the Bézout coefficients are the integers s and t such that as+mt=1.

Once you have found the Bezout coefficients, then:
1=as+mt⟹1≡as(modm),
so that s=a−1 in Zm. Thus, to find a−1, find the Bézout coefficients, and then if 1=as+mt, then s=a−1.