核心思想:每一个合数都是由最小质因数和另一个数得到。摆烂式扩充
推荐习题
def get_primes(n):# get primes in 1 ~ n using euler's method which is O(n)
check = [1] * (n + 1)
primes = []
for i in range(2, n + 1):
if check[i]:
primes.append(i)
for prime in primes:
if i * prime > n:
break
check[i * prime] = 0
if i % prime == 0:
break
return primes