/* -*- coding: utf-8 -*- * * 713.cc: No.713 素数の和 - yukicoder */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; /* constant */ const int MAX_P = 1000; /* typedef */ /* global variables */ bool primes[MAX_P + 1]; /* subroutines */ int gen_primes(int maxp) { memset(primes, true, sizeof(primes)); primes[0] = primes[1] = false; int p, sum = 0; for (p = 2; p * p <= maxp; p++) if (primes[p]) { sum += p; for (int q = p * p; q <= maxp; q += p) primes[q] = false; } for (; p <= maxp; p++) if (primes[p]) sum += p; return sum; } /* subroutines */ /* main */ int main() { int n; scanf("%d", &n); int sum = gen_primes(n); printf("%d\n", sum); return 0; }