diff --git a/cyaron/math.py b/cyaron/math.py index 210ff62..f08eac6 100644 --- a/cyaron/math.py +++ b/cyaron/math.py @@ -226,7 +226,7 @@ def catalan_number(n): def prime_sieve(n): """ Return a list of prime numbers from 2 to a prime < n. Very fast (n<10,000,000) in 0.4 sec. - + Example: >>>prime_sieve(25) [2, 3, 5, 7, 11, 13, 17, 19, 23] @@ -234,11 +234,12 @@ def prime_sieve(n): Algorithm & Python source: Robert William Hanks http://stackoverflow.com/questions/17773352/python-sieve-prime-numbers """ - sieve = [True] * int(n/2) + sieve = [True] * (n//2) for i in range(3,int(n**0.5)+1,2): - if sieve[int(i/2)]: - sieve[i*int(i/2)::i] = [False] * (int((n-i*i-1)/(2*i))+1) - return [2] + [2*i+1 for i in range(1,int(n/2)) if sieve[i]] + if sieve[i//2]: + sieve[i*i//2::i] = [False] * ((n-i*i-1)//(2*i)+1) + return [2] + [2*i+1 for i in range(1,n//2) if sieve[i]] + #--- bezout coefficients--------------------------------------------------------------------------