'''-The sieve of Eratosthenes is an algorithm used to find prime numbers, less than or equal to a given value.-Illustration: https://upload.wikimedia.org/wikipedia/commons/b/b9/Sieve_of_Eratosthenes_animation.gif'''from __future__ import print_functionfrom math import sqrtdef SOE(n):check = round(sqrt(n)) #Need not check for multiples past the square root of nsieve = [False if i <2 else True for i in range(n+1)] #Set every index to False except for index 0 and 1for i in range(2, check):if(sieve[i] == True): #If i is a primefor j in range(i+i, n+1, i): #Step through the list in increments of i(the multiples of the prime)sieve[j] = False #Sets every multiple of i to Falsefor i in range(n+1):if(sieve[i] == True):print(i, end=" ")
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。