fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define int long long int
  4. #define double long double
  5. #define print(a) for(auto x : a) cout << x << " "; cout << endl
  6.  
  7.  
  8. const int M = 1000000007;
  9. const int INF = 2e9+1;
  10. const int LINF = 2000000000000000001;
  11.  
  12. inline int power(int a, int b, int mod=M) {
  13. int x = 1;
  14. a %= mod;
  15. while (b) {
  16. if (b & 1) x = (x * a) % mod;
  17. a = (a * a) % mod;
  18. b >>= 1;
  19. }
  20. return x;
  21. }
  22.  
  23.  
  24. //_ ***************************** START Below *******************************
  25.  
  26. const int N = 1e7+1;
  27.  
  28. vector<bool> isPrime;
  29. vector<int> primes;
  30.  
  31. void seive(){
  32. isPrime.assign(N+1, 1);
  33. isPrime[0] = isPrime[1] = 0;
  34.  
  35. for(int i=2; i*i<=N; i++){
  36. if(isPrime[i] == 0) continue;
  37. for(int j=i*i; j<=N; j+=i){
  38. isPrime[j] = 0;
  39. }
  40. }
  41.  
  42. unordered_set<int> st;
  43. for(int x=1; x<=10000; x++){
  44. for(int y=1; y<=100; y++){
  45. int p = x*x + y*y*y*y;
  46. if(p<=N && isPrime[p]){
  47. if(st.count(p) == 0){
  48. primes.push_back(p);
  49. }
  50. st.insert(p);
  51. }
  52. }
  53. }
  54.  
  55. sort(begin(primes), end(primes));
  56. }
  57.  
  58.  
  59. int consistency(int n){
  60.  
  61. auto ans = upper_bound(begin(primes), end(primes), n) - begin(primes);
  62.  
  63. return ans;
  64.  
  65. }
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81. int practice(int n){
  82.  
  83.  
  84. return 0;
  85. }
  86.  
  87.  
  88.  
  89.  
  90.  
  91. void solve() {
  92. static int _ = (seive(), 0);
  93.  
  94.  
  95. int n;
  96. cin>> n;
  97.  
  98.  
  99. cout << consistency(n) << endl;
  100.  
  101.  
  102. }
  103.  
  104.  
  105.  
  106.  
  107.  
  108. int32_t main() {
  109. ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  110.  
  111. int t = 1;
  112. cin >> t;
  113. while (t--) {
  114. solve();
  115. }
  116.  
  117. return 0;
  118. }
Success #stdin #stdout 0.04s 5320KB
stdin
4
1
2
10
9999999
stdout
0
1
2
13175