Last active
July 5, 2016 07:01
-
-
Save LotusChing/5136c12f4e4cf08c51c158cebe4b97c2 to your computer and use it in GitHub Desktop.
素数测试
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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