fork(1) download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. #define MAX_PRIME 20000000
  6.  
  7. long long int sum = 0;
  8. int noPrimes = 0;
  9. bool isNotPrime[MAX_PRIME]= {};
  10.  
  11. void count()
  12. {
  13. for (int i = 2; i < MAX_PRIME; i++)
  14. {
  15. if (!isNotPrime[i])
  16. {
  17. for (int j = i + i; j < MAX_PRIME; j += i)
  18. {
  19. isNotPrime[j] = true;
  20. }
  21. noPrimes++;
  22. sum += i;
  23. }
  24. }
  25. }
  26.  
  27. int main()
  28. {
  29. count();
  30. cout << "noPrimes = " << noPrimes << endl;
  31. cout << "sum = " << sum << endl;
  32. return 0;
  33. }
Success #stdin #stdout 0.85s 22824KB
stdin
Standard input is empty
stdout
noPrimes = 1270607
sum = 12272577818052