fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define io(x) if(fopen(x".INP", "r")){freopen(x".INP","r",stdin);freopen(x".OUT","w",stdout);}
  4. #define uf(i, a, b) for (int i = (a); i <= (b); i++)
  5. #define df(i, a, b) for (int i = (a); i >= (b); i--)
  6. #define rep(i, n) for (int i = 1; i <= (n); i++)
  7. #define pb push_back
  8. #define fi first
  9. #define se second
  10. #define sz(x) (int)((x).size())
  11. #define ms(a, v) memset(a, v, sizeof(a))
  12. #define bit(i, x) ((x >> i) & 1)
  13.  
  14. template <class T> bool maximize(T &a, const T &b){ return (a < b ? a = b, 1 : 0); }
  15. template <class T> bool minimize(T &a, const T &b){ return (a > b ? a = b, 1 : 0); }
  16.  
  17. typedef long long ll;
  18. typedef pair<int, int> pii;
  19. typedef vector<int> vi;
  20.  
  21. // End of template
  22.  
  23. const int MOD = 1e9+7;
  24. const int maxn = 3e6+5;
  25. const int inf = 2e9+123;
  26.  
  27. int n;
  28. vi p;
  29. bool prime[maxn];
  30.  
  31. void sieve(int n, ll &res){
  32. int super = 3*n;
  33. rep(i, super-1) prime[i] = 1;
  34. for (int i = 2; i*i < super; i++){
  35. if (!prime[i]) continue;
  36. for (int j = i*i; j < super; j += i) prime[j] = 0;
  37. }
  38. uf(i, 3, super-1) if (prime[i]){
  39. res += i/2;
  40. res -= ((i/2 - n) > 0 ? (i/2 - n) : 0);
  41. res -= ((i - n - 1) / 2 > 0 ? (i - n - 1) / 2 : 0);
  42. // cout << i << ' ' << res << '\n';
  43. }
  44. }
  45.  
  46. void solve(){
  47. cin >> n;
  48. ll res = 0;
  49. sieve(n, res);
  50. cout << res;
  51. }
  52. int main(){
  53. ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  54. io("TEST");
  55. // freopen("TEST.INP","r",stdin);
  56. // freopen("TEST.ANS","w",stdout);
  57. int numTest;
  58. numTest = 1;
  59. // cin >> numTest;
  60. while(numTest--){
  61. solve();
  62. }
  63. return 0;
  64. }
Success #stdin #stdout 0.01s 5272KB
stdin
Standard input is empty
stdout
Standard output is empty