<p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; outline: none; color: rgb(102, 102, 102); font-family: Arial, 'Hiragino Sans GB', SimSun, 宋体, Georgia, serif; line-height: 22px; white-space: pre-wrap;"><strong>题目内容:</strong></p><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; outline: none; color: rgb(102, 102, 102); font-family: Arial, 'Hiragino Sans GB', SimSun, 宋体, Georgia, serif; line-height: 22px; white-space: pre-wrap;">我们认为2是第一个素数,3是第二个素数,5是第三个素数,依次类推。</p><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; outline: none; color: rgb(102, 102, 102); font-family: Arial, 'Hiragino Sans GB', SimSun, 宋体, Georgia, serif; line-height: 22px; white-space: pre-wrap;">现在,给定两个整数n和m,0<n<=m<=200,你的程序要计算第n个素数到第m个素数之间所有的素数的和,包括第n个素数和第m个素数。</p><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; outline: none; color: rgb(102, 102, 102); font-family: Arial, 'Hiragino Sans GB', SimSun, 宋体, Georgia, serif; line-height: 22px; white-space: pre-wrap;"><strong>输入格式:</strong>
</p><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; outline: none; color: rgb(102, 102, 102); font-family: Arial, 'Hiragino Sans GB', SimSun, 宋体, Georgia, serif; line-height: 22px; white-space: pre-wrap;">两个整数,第一个表示n,第二个表示m。</p><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; outline: none; color: rgb(102, 102, 102); font-family: Arial, 'Hiragino Sans GB', SimSun, 宋体, Georgia, serif; line-height: 22px; white-space: pre-wrap;"><strong>输出格式:</strong>
</p><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; outline: none; color: rgb(102, 102, 102); font-family: Arial, 'Hiragino Sans GB', SimSun, 宋体, Georgia, serif; line-height: 22px; white-space: pre-wrap;">一个整数,表示第n个素数到第m个素数之间所有的素数的和,包括第n个素数和第m个素数。</p><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; outline: none; color: rgb(102, 102, 102); font-family: Arial, 'Hiragino Sans GB', SimSun, 宋体, Georgia, serif; line-height: 22px; white-space: pre-wrap;"><strong>输入样例:</strong>
</p><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; outline: none; color: rgb(102, 102, 102); font-family: Arial, 'Hiragino Sans GB', SimSun, 宋体, Georgia, serif; line-height: 22px; white-space: pre-wrap;">2 4</p><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; outline: none; color: rgb(102, 102, 102); font-family: Arial, 'Hiragino Sans GB', SimSun, 宋体, Georgia, serif; line-height: 22px; white-space: pre-wrap;"><strong>输出样例:</strong>
</p><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; outline: none; color: rgb(102, 102, 102); font-family: Arial, 'Hiragino Sans GB', SimSun, 宋体, Georgia, serif; line-height: 22px; white-space: pre-wrap;">15</p>
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int m= in.nextInt();
int i,j,sum=0,count=0;
boolean tag=true;
double num;
for(i=2;count<m;i++){
num = Math.sqrt((double) i);
tag=true;
for(j =2;j<=num;j++)//判断是否是素数,tag为true时,为素数
if(i%j==0){
tag=false;break;
}
if(tag){
count++;
if(count>=n)//如果是素数且在n到m之间,求和
sum+=i;
}
}
System.out.println(sum);
}
}