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 简短祝福语毛笔字