赞
踩
代码思路仅供参考,欢迎大家批评指正!
本题要求显示给定整数M和N区间内素数并对它们求和。
# By jurio. import math M, N = map(int,input().split()) M = 2 if M == 1 else M a = list(range(M,N+1)) for x in range(M,N+1): for m in range(2,int(math.sqrt(x)+1)): if x%m==0: a.remove(x) break for i in range(len(a)): if (i+1)%5!=0: print(a[i],end=' ') else: print(str(a[i])+" ") if len(a)%5==0: print("amount="+str(len(a)),"sum="+str(sum(a))) else: print("\namount="+str(len(a)),"sum="+str(sum(a)))
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。