You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
functionerichsen(n){constisPrimeList=newArray(n+1).fill(1)for(i=2;i<=n/i;i++){if(isPrimeList[i]===1){// delete i Multiple numberfor(letj=i*i;j<=n;j+=i){isPrimeList[j]=0}}}letcount=0for(leti=2;i<=n;i++){if(isPrimeList[i]===1)count++}returncount}
euler
classSolution {
privatefinalstaticintMX = 1000000;
privatefinalstaticArrayList<Integer> primes = newArrayList<Integer>();
static {
boolean[] noPrime = newboolean[MX + 1];
for (inti = 2; i <= MX; i++) {
if (!noPrime[i]) {
primes.add(i);
}
for (intp: primes) {
if (i * p > MX) break;
noPrime[i * p] = true;
if (i % p == 0) {
break;
}
}
}
// optional suffix, to avoid overflowprimes.add(MX + 1);
primes.add(MX + 1);
}
// todo
}
erichsen
euler
The text was updated successfully, but these errors were encountered: