Java中的模块化乘法逆
java.math.BigInteger.modInverse(BigIntegerm)返回一个BigInteger,其值为(this-1modm)。使用这种方法,您可以计算给定数字的模乘逆。
程序
import java.math.*;
public class BigIntegerDemo {
public static void main(String[] args) {
//创建3个BigInteger对象
BigInteger bi1, bi2, bi3;
//创建一个BigInteger指数
BigInteger exponent = new BigInteger("2");
bi1 = new BigInteger("7");
bi2 = new BigInteger("20");
//使用bi2和exp对bi1执行modPow操作
bi3 = bi1.modPow(exponent, bi2);
String str = bi1 + "^" +exponent+ " mod " + bi2 + " is " +bi3;
//打印bi3值
System.out.println( str );
}
}输出结果
7^2 mod 20 is 9
热门推荐
10 祝孙辈生日祝福语简短
11 恋人跨年祝福语大全简短
12 考大学敬酒简短祝福语
13 开工投产大吉祝福语 简短
14 偶然结婚祝福语朋友简短
15 感谢学长学姐祝福语简短
16 戏精的祝福语简短
17 我要结婚祝福语简短
18 婚前女儿生日祝福语简短