这是一个正在寻找一些最初的mersenne素数的程序,我不知道出什么问题了。当我运行它说给出错误的结果。编译时没有错误,但是程序只是没有给出正确的结果。有人知道怎么了吗? (同样,这确实不是问题,但是它应该在30处停止,直到应该上升到2147483647。)
import java.util.*;
import java.math.*;
public class Main {
public static void main(String[] args) {
BigInteger bi1 = BigInteger.valueOf(0);
BigInteger one;
BigInteger zero;
BigInteger limit;
Long oneL = new Long(1L);
Long zeroL = new Long(0L);
Long bi1L = new Long(1L);
Long limitL = new Long(2147483647L);
one = BigInteger.valueOf(oneL);
zero = BigInteger.valueOf(zeroL);
bi1 = BigInteger.valueOf(oneL);
limit = BigInteger.valueOf(limitL);
bi1 = BigInteger.valueOf(zeroL);
int res3;
for (res3 = bi1.compareTo(limit); res3 == 0 | res3 == -1; bi1 = bi1.add(one)) {
BigInteger a;
BigInteger apog;
int intbi1;
intbi1 = bi1.intvalue();
apog = BigInteger.valueOf(2).pow(intbi1);
a = apog.subtract(one);
boolean isPrime = true;
BigInteger b;
Long bL = new Long(2L);
b = BigInteger.valueOf(bL);
int res;
for (res = b.compareTo(a); res == -1; b = b.add(one)) {
int res2;
res2 = a.mod(b).compareTo(zero);
BigInteger c;
c = a.mod(b);
int intc;
intc = c.intvalue();
int res4;
res4 = a.mod(b).compareTo(zero);
if (res4 == 0) {
isPrime = false;
break;
}
res = b.compareTo(a);
}
if (isPrime) {
System.out.println("YES!! " + bi1);
} else {
System.out.println("No,not prime " + bi1);
isPrime = true;
}
}
}
}