完成python作业
6-2 计算素数和
本题要求计算输入两个正整数x,y(x<=y,包括x,y)素数和。函数isPrime用以判断一个数是否素数,primeSum函数返回素数和
import math def primeSum(x,y): MAX_INT=y MIN_INT=x marks_bool = [True] * (MAX_INT + 1) for i in range(2,int(math.sqrt(MAX_INT)) + 1): j = i k = j while j * k <= MAX_INT: marks_bool[j * k] = False k += 1 sum=0 for i in range(2,MAX_INT + 1): if marks_bool[i] is True: if(i>=MIN_INT): sum+=i return sum
标签:26,2024.3,MIN,INT,MAX,sum,进度,math From: https://www.cnblogs.com/Sunyiran/p/18122647