Java中的模幂(模运算中的幂)
java.math.BigInteger.modPow(BigInteger的指数,BigInteger的米)返回一个BigInteger,其值是(这<SUP>指数</SUP>modM)表示。与pow不同,此方法允许使用负指数。您可以使用此方法计算模幂。
程序
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 朋友入伙搬家祝福语简短