Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

Sieve of Eratosthenes

	boolean[] seiveOfEnthorism(int n) {
        if(n <= 1)
            return new boolean[0];
        boolean prime[] = new boolean[n + 1];
        Arrays.fill(prime, true);
        prime[0] = prime[1] = false;
        int sqr = (int)Math.sqrt(n);
        for(int i = 2; i <= sqr; i++) {
            if(prime[i]) {
                int j = 2;
                while(i * j <= n) {
                    prime[i * j] = false;
                    j++;
                }
            }
        }
        return prime;
    }
 
PREVIOUS NEXT
Tagged: #Sieve #Eratosthenes
ADD COMMENT
Topic
Name
1+8 =