Eratosties筛-寻找Python的Primes
def primes_sieve(limit): limitn = limit+1 primes = range(2, limitn) for i in primes: factors = range(i, limitn, i) for f in factors[1:]: if f in primes: primes.remove(f) return primesprint primes_sieve(2000)
最新情况:
def primes_sieve1(limit): limitn = limit+1 primes = dict() for i in range(2, limitn): primes[i] = True for i in primes: factors = range(i,limitn, i) for f in factors[1:]: primes[f] = False return [i for i in primes if primes[i]==True]print primes_sieve1(2000000)
海绵宝宝撒
慕姐8265434
米脂