I found this code here on StackOverflow:
public static BitSet computePrimes(int limit) {
final BitSet primes = new BitSet();
primes.set(0, false);
primes.set(1, false);
primes.set(2, limit, true);
for (int i = 0; i * i < limit; i++) {
if (primes.get(i)) {
for (int j = i * i; j < limit; j += i) {
primes.clear(j);
}
}
}
return primes;
}
but I'm struggling to understand how to get it working above Integer.MAX_VALUE.
I know i have to use long, but what do I have to change (in the loops) in this method to get Primes from Integer.MAX_VALUE to 3037000499L, or is it even possible?