Java中的BigInteger.isProbablePrime()方法
如果此BigInteger可能是素数,则BigInteger.isProbablePrime(int确定性)返回true,如果绝对是复合的,则返回false。如果确定度≤0,则返回true。
在这里,“确定性”参数是对呼叫者愿意忍受的不确定性的度量:如果呼叫返回true,则此BigInteger为质数的概率超过(1/1/2确定性)。该方法的执行时间与该参数的值成正比。
以下是一个例子-
示例
import java.math.BigInteger;
public class Demo {
public static void main(String[] argv) throws Exception {
//创建3个BigInteger对象
BigInteger bi1, bi2;
//创建3个布尔对象
Boolean b1, b2, b3;
bi1 = new BigInteger("11");
bi2 = new BigInteger("20");
// isProbablePrime()
b1 = bi1.isProbablePrime(1);
b2 = bi2.isProbablePrime(1);
String str1 = bi1+ " is prime with certainty 1 is " +b1;
String str2 = bi2+ " is prime with certainty 1 is " +b2;
System.out.println(str1);
System.out.println(str2);
}
}输出结果
11 is prime with certainty 1 is true 20 is prime with certainty 1 is false
热门推荐
3 祝福语简短的微信
10 幼儿祝福语大全简短贺卡
11 感谢教官文案祝福语简短
12 鼠年同事祝福语简短创意
13 元旦祝福语 简短独特群发
14 妈咪跟我生日祝福语简短
15 给儿子新婚祝福语简短
16 伴娘祝福语长文案简短
17 恭喜高考完祝福语简短
18 生日祝福语送老公简短