fork(6) download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const int NMAX = (int)1e8;
  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 0.19s 9732KB
stdin
Standard input is empty
stdout
sum = 279209790387276
cnt = 5761455