解题思路:
注意事项:
参考代码:
import java.util.Scanner;
public class Main {
public static int isprime(int X){
int flag = 0 ;
for(int i=2;i<=X;i++){
if(X%i==0&&X!=i)
break;
else if(i==X)
flag = 1 ;
}
return flag;
}
public static void main(String[] arg){
Scanner sc = new Scanner(System.in);
int m = sc.nextInt();
int n = sc.nextInt();
int sum = 0;
for(int X=m;X<=n;X++){
if(isprime(X)==1)
sum+=X;
}
System.out.print(sum);
}
}
0.0分
3 人评分