I think I'm using the Eratosthenes sieve, since an array can't take long values as indexes, I get the memory error even when I use casting. Should I rather create a Map or List containing long values and compute that way ? This is the code: **
int max = 2000000;
int sum = 0;
boolean[] list = new boolean[max];
list[0] = false;
list[1] = false;
for (int i = 2; i < max; i++) {
list[i] = true;
}
for (int i = 2; i < max; i++) {
for (int j = 1; j < max; j++) {
if(list[j]&&i*j<max){
list[i*j] = false;
}
}
if(list[i]){
sum+=i;
}
}
System.out.println(sum);
**