fork(6) download
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. #define ISBITSET(x, i) (( x[i>>3] & (1<<(i&7)) ) != 0)
  5. #define SETBIT(x, i) x[i>>3] |= (1<<(i&7));
  6. #define CLEARBIT(x, i) x[i>>3] &= (1<<(i&7)) ^ 0xFF;
  7.  
  8. long long sumPrimes(int n) {
  9. char b[n/8+1];
  10. long long i, p;
  11. long long s = 0;
  12.  
  13. memset(b, 255, sizeof(b));
  14. for (p=2; p<n; p++) {
  15. if (ISBITSET(b,p)) {
  16. //printf("%d\n", p);
  17. s += p;
  18. for (i=p*p; i<n; i+=p) {
  19. CLEARBIT(b, i); }}}
  20. return s; }
  21.  
  22. int main(void) {
  23. printf("%lld\n", sumPrimes(2000000));
  24. return 0; }
Success #stdin #stdout 0.03s 2416KB
stdin
Standard input is empty
stdout
142913828922