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

Answer by Madiyar for Sieve of Eratosthenes - Finding Primes Python

$
0
0

The fastest implementation I could come up with:

isprime = [True]*Nisprime[0] = isprime[1] = Falsefor i in range(4, N, 2):    isprime[i] = Falsefor i in range(3, N, 2):    if isprime[i]:        for j in range(i*i, N, 2*i):            isprime[j] = False

Viewing all articles
Browse latest Browse all 28

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>