原题链接:PTA | 程序设计类实验辅助教学平台
Tips:以下Python代码仅个人理解,非最优算法,仅供参考!多学习其他大佬的AC代码!
def is_prime(n):
if n <=3:
return n>=2
if n % 6 not in (5, 1):
return False
for i in range(5, int(n**0.5)+1, 6):
if n % i == 0 or n % (i+2) == 0:
return False
return True
def main():
date = input()
all_flag = True
for i in range(len(date)):
stat = is_prime(int(date))
if stat:
stat = 'Yes'
else:
stat = 'No'
all_flag = False
print(date, stat)
date = date[1:]
if all_flag:
print('All Prime!')
main()
标签:False,stat,return,Python,int,flag,1114,date,PAT
From: https://blog.csdn.net/m0_56677113/article/details/142961750