所以我正在编写一个素性测试程序,在我的代码中的某个地方我有这个:
BigInteger temp = BigInteger.valueOf(0);
BigInteger p_Big = BigInteger.valueOf(p); // p is just an integer
temp = power(a, p-1); // a method to calculate a^(p-1)
temp = temp.mod(p_Big);
if(temp != BigInteger.ONE){
return false;
}
问题是,我得到false
对于应该返回 true
的值,奇怪的是,当我这样做时
System.out.println(temp+","+BigInteger.ONE);
对于p = 5, a = 2
我明白
1,1
那么是什么导致它返回 false
?
最佳答案
替换
if(temp != BigInteger.ONE)
与
if(!temp.equals(BigInteger.ONE))
关于java - 简单语句中的BigInteger逻辑问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33987275/