前六个质数是2,3,5,7,11和13,其中第6个是13.
第10001个质数是多少?
原题目链接:Problem 7
暴力算就行
public class Problem7 { public static void main(String[] args) { int index = 0; int prime = 2; while (index != 10001) { if(isPrime(prime)){ index ++; } prime ++; } System.out.println(prime -1); } public static Boolean isPrime(int value) { Boolean flag = true; for (int i = 2; i <= Math.sqrt(value); i++) { if (value % i == 0) { flag = false; break; } } return flag; } }