a121.
質數又來囉
| From: [101.12.21.183] |
發表日期
:
2023-04-11 22:24
from math import sqrt
def prime_number(x):
if x==1:
return False
elif x==2 or x==3 or x==5 or x==7 or x==11:
return True
elif (x%6!=5 and x%6!=1)or x%5==0 or x%7==0 or x%11==0:
return False
else:
# print(x)
for i in range(3,int(sqrt(x))+1,2):
if x%i==0:
return False
return True
while True:
try:
start,end=map(int,input().split())
if start>end:
pass
count=0
for i in range(start,end+1):
test=prime_number(i)
if test:
count+=1
print(count)
except(EOFError):
break
這是我的寫法,已經盡可能縮短執行時間了,而且我不想用列表法