fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const long long NMAX = (long long)1e9;
  5. int main() {
  6. bitset<NMAX / 2> bits;
  7. bits.set();
  8. auto sum = 2LL;
  9. int cnt = 1;
  10. for (int i = 3; i / 2 < bits.size(); i = 2 * bits._Find_next(i / 2) + 1) {
  11. sum += i;
  12. ++cnt;
  13. for (auto j = (int64_t) i * i / 2; j < bits.size(); j += i)
  14. bits[j] = 0;
  15. }
  16. cout << "sum = " << sum << endl;
  17. cout << "cnt = " << cnt << endl;
  18. return 0;
  19. }
Success #stdin #stdout 4.8s 64560KB
stdin
Standard input is empty
stdout
sum = 24739512092254535
cnt = 50847534