fork(3) download
  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cmath>
  4. using namespace std;
  5. #define n 163842
  6. int main()
  7. {
  8. int a[81922];
  9. int i,j,s,count,k,t;
  10. cin>>t;
  11. while(t--)
  12. {
  13. count=0;
  14. cin>>k;
  15. for(i=2;i<n>>1;i++)
  16. a[i]=0;
  17. s=int(sqrt((double )n));
  18. ///cout<<s;
  19. for(i=3;i<=s;i+=2)
  20. {
  21. if(a[i>>1]==0)
  22. {
  23. for( j = i * i; j <= n; j += i + i )
  24.  
  25. {
  26. a[j>>1]=1;
  27. }
  28. }
  29. }
  30. //cout<<2;
  31. if(k==1)
  32. cout<<2<<endl;
  33. for(i=3;i<=n;i+=2)
  34. {
  35. if(a[i>>1]==0)
  36. {
  37. ///cout<<"prime="<<i<<endl;
  38.  
  39. count++;
  40. if(count==k-1)
  41. {
  42. cout<<i<<endl;
  43. break;
  44. }
  45. }
  46.  
  47.  
  48. }
  49. //cout<<count;
  50.  
  51.  
  52. }
  53.  
  54. }
  55.  
Success #stdin #stdout 0s 15432KB
stdin
5
1
2
3
4
5
stdout
2
3
5
7
11