結果

問題 No.713 素数の和
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2018-07-15 10:56:43
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,710 bytes
コンパイル時間 1,816 ms
コンパイル使用メモリ 166,272 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-23 13:03:31
合計ジャッジ時間 1,882 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
vector<int> makePrimes(int n) {
    vector<int> res, primes(n + 1, 1);
    primes[0] = primes[1] = 0;
    rep(i, 2, sqrt(n)) if (primes[i]) for (int j = 0; i * (j + 2) <= n; j++) primes[i * (j + 2)] = 0;
    rep(i, 2, n + 1) if (primes[i]) res.push_back(i);
    return res;
}
/*---------------------------------------------------------------------------------------------------
            ∧_∧  
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     
    /   \     | |     
    /   / ̄ ̄ ̄ ̄/  |  
  __(__ニつ/     _/ .| .|____  
     \/____/ (u ⊃  
---------------------------------------------------------------------------------------------------*/






int N;
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N;
    auto pv = makePrimes(N);
    int ans = 0;
    fore(p, pv) ans += p;
    cout << ans << endl;
}
0