fork download
  1. #include<iostream>
  2. #include<cmath>
  3. #include<cstdio>
  4. using namespace std;
  5. int N = 163842, status[163842]= {0};
  6. int main()
  7. {
  8. int i, j, sqrtN,count,k,t;
  9. cin>>t;
  10. while(t--)
  11. {
  12. cin>>k;
  13. count=0;
  14. sqrtN = int ( sqrt((double) N ));
  15. for( i = 3; i <= sqrtN; i += 2 )
  16. {
  17. if( status[i] == 0 )
  18. {
  19. for( j = i * i; j <= N; j += i )
  20. {
  21. status[j] = 1;
  22. }
  23. }
  24. }
  25. if(k==1)
  26. cout<<2<<endl;
  27. else
  28. {
  29. for( i = 3; i <= N; i += 2 )
  30. {
  31. if(status[i]==0)
  32. {
  33. count++;
  34. if(count==k-1)
  35. {
  36. cout<<i<<endl;
  37. break;
  38. }
  39.  
  40. }
  41. }
  42. }
  43.  
  44. }
  45. }
Success #stdin #stdout 0s 16704KB
stdin
5
15000
14999
14998
14997
14996
stdout
163841
163819
163811
163789
163781