题解 | #Prime Number#
Prime Number
https://www.nowcoder.com/practice/c5f8688cea8a4a9a88edbd67d1358415
#include <stdio.h> int main() { int n,a[100007]={0}; int i=0; int j,flag; while (scanf("%d",&n)!=EOF) { //scanf("%d",&n); if(n==1){ printf("2\n"); break; } a[0]=2; i=1; j=3; flag=1; while(i<n){ flag=1; for(int k=0;k<i;k++){ if(j%a[k]==0){ flag=0; break; } } if(flag==1){ a[i]=j; i++; } j++; } printf("%d\n",j-1); } }