题解 | #Prime Number#
Prime Number
https://www.nowcoder.com/practice/c5f8688cea8a4a9a88edbd67d1358415
#include "stdio.h" bool primeJudge(int x){ for (int i = 2; i*i <= x ; ++i) {//a*b=c,所以i(<sqr(x))如果是x的约数,那么必然有一个约数大于sqr(x) //所以判断到sqrt(x)即可,不然会超时。当然,打表也是一种做法。 if(x%i == 0) return false; } return true; } int main(){ int k;int num; while (scanf("%d",&k) != EOF){ num = 2; while (k > 0){ if(primeJudge(num)){ --k; } ++num; } printf("%d\n",num-1); } }