程序员的自我修养

1013 数素数(java)

2019-02-27  本文已影响0人  殁月

import java.util.Scanner;

public class Main {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

int M = sc.nextInt();

int N = sc.nextInt();

int count = 0;

int c = 0;

for(int i = 2;i<200000;i++){

if(isPrime(i))

count++;

if(count >= M&&isPrime(i)){

c++;

if(c%10 == 0)

System.out.println(i);

else if(c != N-M+1)

System.out.print(i+" ");

else System.out.print(i);

}

if(count >= N)

break;

}

}

public static boolean isPrime(int n) {

for (int i = 2; i <= Math.sqrt(n); i++) {

if (n % i == 0)

return false;

}

return true;

}

}

上一篇下一篇

猜你喜欢

热点阅读