Skip to content

Instantly share code, notes, and snippets.

@LotusChing
Last active July 5, 2016 07:01
Show Gist options
  • Save LotusChing/5136c12f4e4cf08c51c158cebe4b97c2 to your computer and use it in GitHub Desktop.
Save LotusChing/5136c12f4e4cf08c51c158cebe4b97c2 to your computer and use it in GitHub Desktop.
素数测试
lst = [2, 3, 4, 5, 6, 7]
sum = 0
def Prime(n):
for i in range(2, n):
if n % i == 0:
return False
else:
return True
for i in lst:
if Prime(i): sum += 1
print(sum)
"""
n=2 list=[] sum = 1
n=3 list=[2] sum = 2
n=4 list=[2,3] sum = 2
n=5 list=[2,3,4] sum = 3
n=6 list=[2,3,4,5] sum = 3
n=7 list=[2,3,4,5,6] sum = 4
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment