Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #define N 2e6
- int main(void)
- {
- char *s = calloc(N+1, sizeof(char));
- size_t p=2, i;
- unsigned long long sum=0;
- while (p*p < N) {
- for (i=p*p; i<=N; i+=p) s[i] = 1;
- while (s[++p]);
- }
- for (i=2; i<N; ++i)
- if (s[i]==0) sum+=i;
- printf("%llu\n", sum);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement