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

Answer by HoangYell for Sieve of Eratosthenes - Finding Primes Python

$
0
0

here is my solution, the same as Wikipedia

import mathdef sieve_of_eratosthenes(n):    a = [i for i in range(2, n+1)]    clone_a = a[:]    b = [i for i in range(2, int(math.sqrt(n))+1)]    for i in b:        if i in a:            c = [pow(i, 2)+(j*i) for j in range(0, n+1)]            for j in c:                if j in clone_a:                    clone_a.remove(j)    return clone_aif __name__ == '__main__':    print(sieve_of_eratosthenes(23))

Viewing all articles
Browse latest Browse all 28

Trending Articles