package nm质数和;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
int n , m;
int cnt = 0;
int sum = 0;
int x, y;
Scanner in = new Scanner(System.in);
n = in.nextInt();
m = in.nextInt();
for ( x=2; cnt<n; x=x+1 )
{
int a = 1;
for(int i=2; i<x; i=i+1 )
{
if( x % i == 0 )
{
a = 0;
break;
}
}
if( a == 1)
{
cnt = cnt + 1;
}
}
y = x -1;
if ( n != 1 ) cnt = cnt - 1;else cnt = 0;
for ( y = y; cnt<m; y= y+1 )
{
int a = 1;
for( int i=2; i<y; i=i+1 )
{
if( y % i == 0 )
{
a = 0;
break;
}
}
if( a == 1)
{
cnt = cnt + 1;
sum = sum + y;
}
}
System.out.println( sum );
}
}
第n个至第m个素数的和
最新推荐文章于 2020-12-17 15:42:10 发布