// yukicoder: No.713 素数の和 // 2019.4.14 bal4u #include #include #define MAX 1000 #define SQRT 31 char prime[MAX+5]; // 1: if prime void sieve() { int i, j; memset(prime, 1, sizeof(prime)); for (i = 4; i <= MAX; i+=2) prime[i] = 0; prime[0] = prime[1] = 0, prime[2] = 1; for (i = 3; i <= SQRT; i += 2) if (prime[i]) { for (j = i * i; j < MAX; j += i) prime[j] = 0; } } int main() { int i, N, ans; sieve(); scanf("%d", &N); ans = 0; for (i = 2; i <= N; i++) if (prime[i]) ans += i; printf("%d\n", ans); return 0; }