Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

sieve of eratosthenes

function solution(n) {
   const numArr = new Array(n + 1);
   numArr.fill(true);
   numArr[0] = numArr[1] = false;
   for (let i = 2; i <= Math.sqrt(n); i++) {
      for (let j = 2; i * j <= n; j++) {
          numArr[i * j] = false;
      }
   }
   return numArr.filter(Boolean).length;
}

Source by programmers.co.kr #
 
PREVIOUS NEXT
Tagged: #sieve #eratosthenes
ADD COMMENT
Topic
Name
8+7 =