|
|
back to boardGetting TLE What is the problem with my code? #include <iostream> using namespace std; #include <cmath> bool check_prime(double n) { int c; for (c=2;c<= sqrt(n);c++) { if((int) n%c==0) return 0; } if(c==(int) n) return 1; } int nth_prime(int n){ int m=1; while (n>0) { m++; if (m == 2) { n--; } if (m%2!=0) { if (check_prime(m)==1) { n--; } } } return m;
} int main() { int n,m,i,a[15000],s; scanf("%d",&n); for(i=0;i<n;i++){ scanf("%d",&a[i]); } for(i=0;i<n;i++){ s = nth_prime(a[i]); printf("%d\n",s); } return 0; } |
|
|