Question: I'm trying to disable the checkbox for specific field on the base of condition,

```
if (value == 3)
ko.observable(value);

```

Answer: 
1.94 seconds for 10.000.000

```
def sieve_eratosthene(limit):

    primes = [True] * (limit+1)
    iter = 0

    while iter < limit**0.5 :
        if iter < 2:
            primes[iter]= False

        elif primes[iter]:
            for i in range(iter*2, limit+1, iter):
                primes[i] = False

        iter+=1

    return(x for x in range(limit+1) if primes[x])

```
Here's a simple way to do this using NumPy. It is somewhat similar to the OP's idea of indexing instead of looping again inside the main loop, but without the division check, only slicing.

It is also similar to user2357112 supports Monica answer, but this one only considers odd numbers, which makes it faster.

This is a typical odd only sieve: <https://stackoverflow.com/a/20248491/8094047>.

1. Create a bool array of size n.
2. Loop through odd numbers up to square root of n.  
Note: numbers are used interchangeably as indices
3. Mark composite (multiples of primes) numbers as false.

In the end we have a bool array that we can use to check if a number below n is prime (except even numbers, you can check for them without the array, using & 1 or so)

Avg. time for n = 20000000: 0.1063s

```py
import numpy as np
n = 20000000

isprime = np.ones(n, dtype=np.bool)

# odd only sieve
i = 3
while (i * i < n):
    if isprime[i]:
        isprime[i * i:n:2 * i] = False
    i += 2

# test
print(isprime[97]) # should be True

```