题解 | #Prime Number#
Prime Number
https://www.nowcoder.com/practice/c5f8688cea8a4a9a88edbd67d1358415
#include <stdio.h> #include <math.h> #include <stdbool.h> // 判断质数: bool Prime(int x) { if (x == 1) return false; int y = sqrt(x); for (int i = 2; i <= y; i++) { if (x % i == 0) return false; } return true; } int main() { int n; scanf("%d",&n); int i=1; int count=0; while (i) { if(Prime(i)) { count++; if(count==n) { printf("%d\n",i); break; } i++; } else { i++; } } return 0; }