Skip to content

Commit 791a912

Browse files
author
Toto Lin
authored
Merge pull request #30 from MrMorning/patch-1
Update math.py
2 parents 656af22 + 481db67 commit 791a912

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

cyaron/math.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -226,19 +226,20 @@ def catalan_number(n):
226226
def prime_sieve(n):
227227
"""
228228
Return a list of prime numbers from 2 to a prime < n. Very fast (n<10,000,000) in 0.4 sec.
229-
229+
230230
Example:
231231
>>>prime_sieve(25)
232232
[2, 3, 5, 7, 11, 13, 17, 19, 23]
233233
234234
Algorithm & Python source: Robert William Hanks
235235
http://stackoverflow.com/questions/17773352/python-sieve-prime-numbers
236236
"""
237-
sieve = [True] * int(n/2)
237+
sieve = [True] * (n//2)
238238
for i in range(3,int(n**0.5)+1,2):
239-
if sieve[int(i/2)]:
240-
sieve[i*int(i/2)::i] = [False] * (int((n-i*i-1)/(2*i))+1)
241-
return [2] + [2*i+1 for i in range(1,int(n/2)) if sieve[i]]
239+
if sieve[i//2]:
240+
sieve[i*i//2::i] = [False] * ((n-i*i-1)//(2*i)+1)
241+
return [2] + [2*i+1 for i in range(1,n//2) if sieve[i]]
242+
242243

243244

244245
#--- bezout coefficients--------------------------------------------------------------------------

0 commit comments

Comments
 (0)