Quantcast
Channel: Sieve of Eratosthenes - Finding Primes Python - Stack Overflow
Viewing all articles
Browse latest Browse all 28

Answer by nhern121 for Sieve of Eratosthenes - Finding Primes Python

$
0
0
import mathdef sieve(n):    primes = [True]*n    primes[0] = False    primes[1] = False    for i in range(2,int(math.sqrt(n))+1):            j = i*i            while j < n:                    primes[j] = False                    j = j+i    return [x for x in range(n) if primes[x] == True]

Viewing all articles
Browse latest Browse all 28

Trending Articles