Java BigInteger modInverse() 方法

2025 年 3 月 20 日 | 阅读 2 分钟

Java BigInteger 类的 modInverse() 方法用于查找此 BigInteger 值的模逆。此方法返回一个 BigInteger,其值为此 BigInteger mod 参数值的逆。

语法

参数

m - 模数。

返回值

该方法返回 (this-1 mod m)。

Exception

ArithmeticException - 如果 (m ≤ 0)。

注意:如果此 BigInteger 的逆不存在(即,此 BigInteger 与参数值不互质),则此方法会抛出 ArithmeticException。

示例 1

输出

13^-1 % 5 is 2

示例 2

输出

-13^-1 % 5 is 3

示例 3

输出

java.lang.ArithmeticException: BigInteger: modulus not positive

示例 4

输出

java.lang.ArithmeticException: BigInteger: modulus not positive
 
下一主题Java BigInteger