简单语句中的BigInteger逻辑问题
BigInteger logic problems in simple statement
所以我正在编写一个素数测试程序,在我的代码中的某处我有这个:
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
本应 return 编辑 true
的值,奇怪的是,当我这样做时
System.out.println(temp+","+BigInteger.ONE);
p = 5, a = 2
我得到
1,1
那么是什么导致它 return false
?
替换
if(temp != BigInteger.ONE)
和
if(!temp.equals(BigInteger.ONE))
所以我正在编写一个素数测试程序,在我的代码中的某处我有这个:
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
本应 return 编辑 true
的值,奇怪的是,当我这样做时
System.out.println(temp+","+BigInteger.ONE);
p = 5, a = 2
我得到
1,1
那么是什么导致它 return false
?
替换
if(temp != BigInteger.ONE)
和
if(!temp.equals(BigInteger.ONE))