全题解析链接
本题要求统计给定整数M和N区间内素数的个数并对它们求和。
输入格式:
输入在一行中给出两个正整数M和N(1≤M≤N≤500)。
输出格式:
在一行中顺序输出M和N区间内素数的个数以及它们的和,数字间以空格分隔。
输入样例:
10 31
输出样例:
7 143
题解:
- m,n=map(int,input().split())
- sum=count=0
- for i in range(m,n+1):
- if i==1:
- continue
- for j in range(2,i):
- if i%j==0:
- break
- else:
- count+=1
- sum+=i
- print(count,sum)
全题解析链接
本题要求统计给定整数M和N区间内素数的个数并对它们求和。
输入格式:
输入在一行中给出两个正整数M和N(1≤M≤N≤500)。
输出格式:
在一行中顺序输出M和N区间内素数的个数以及它们的和,数字间以空格分隔。
输入样例:
10 31
输出样例:
7 143
题解:
- m,n=map(int,input().split())
- sum=count=0
- for i in range(m,n+1):
- if i==1:
- continue
- for j in range(2,i):
- if i%j==0:
- break
- else:
- count+=1
- sum+=i
- print(count,sum)
评论记录:
回复评论: