//No.713 素数の和 #include #include using namespace std; void col_pnum(bool*,int); int main() { int N; cin >> N; bool* pnum = new bool[N+1]; for (int i = 0; i <= N; i++) { pnum[i] = true; } col_pnum(pnum, N); int cnt = 0; for (int i = 0; i <= N; i++) { if (pnum[i] == true) { cnt += i; } } cout << cnt; return 0; } //Nまでの素数を求める void col_pnum(bool *_pnum,int _N) { _pnum[0] = _pnum[1] = false; for (int i=2; i<_N; i++) { if (_pnum[i] == false)continue; for (int j=2; i*j <= _N; j++) { _pnum[i*j] = false; } } return; }