fork download
  1. #include <bits/stdc++.h>
  2. #include <ext/pb_ds/assoc_container.hpp>
  3. #include <ext/pb_ds/tree_policy.hpp>
  4.  
  5. using namespace std;
  6. using namespace __gnu_pbds;
  7. using ll = long long;
  8. using ld = long double;
  9.  
  10. #define all(x) x.begin(),x.end()
  11. #define v(x) vector<x>
  12. #define nl '\n'
  13. #define fxd(x) fixed << setprecision(x)
  14. template<class t> using ordered_set = tree<t, null_type, less<t>, rb_tree_tag, tree_order_statistics_node_update>;
  15. template<class t> using ordered_multiset = tree<t, null_type, less_equal<t>, rb_tree_tag, tree_order_statistics_node_update>;
  16.  
  17. ll nthprime(ll n)
  18. {
  19. vector<bool> nums(10000000,true);
  20. ll cnt = 0;
  21. ll sz = nums.size() -1;
  22. for (ll i = 2; i <= sz; i++)
  23. {
  24. if(nums[i])
  25. {
  26. cnt++;
  27. if(cnt == n)
  28. {
  29. return i;
  30. }
  31. for (ll j = i*i; j <= sz; j+=i)
  32. {
  33. nums[j] = false;
  34. }
  35.  
  36. }
  37. }
  38. return -1;
  39. }
  40.  
  41. int main()
  42. {
  43. ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
  44. ll n ; cin >> n;
  45. cout << nthprime(n);
  46. }
Success #stdin #stdout 0.06s 5320KB
stdin
Standard input is empty
stdout
-1