結果

問題 No.713 素数の和
ユーザー tactac
提出日時 2019-08-02 18:05:46
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 385 ms / 2,000 ms
コード長 1,064 bytes
コンパイル時間 3,472 ms
コンパイル使用メモリ 166,332 KB
実行使用メモリ 31,976 KB
最終ジャッジ日時 2023-09-18 18:22:05
合計ジャッジ時間 7,770 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 377 ms
31,832 KB
testcase_01 AC 381 ms
31,640 KB
testcase_02 AC 337 ms
31,856 KB
testcase_03 AC 385 ms
31,768 KB
testcase_04 AC 373 ms
31,636 KB
testcase_05 AC 372 ms
31,712 KB
testcase_06 AC 340 ms
31,724 KB
testcase_07 AC 379 ms
31,976 KB
testcase_08 AC 333 ms
31,828 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep3(i, l, n) for (int i = l; i < n; ++i)
#define chmax(a, b) a = (a >= b ? a : b)
#define chmin(a, b) a = (a <= b ? a : b)
#define out(a) cout << a << endl
#define outa(a, n) rep(_, n) cout << a[_] << " "; cout << endl
#define SZ(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
#define FIX(a) fixed << setprecision(a)

vector<int> sieve() {
    const int MAX_N = 7369791 + 1;
    vector<int> v(MAX_N, 0);
    v[0] = v[1] = 1;
    for (int i = 2; i * i <= MAX_N; ++i) {
        int tmp = 2;
        while (tmp * i <= MAX_N) {
            v[tmp++ * i] = 1;
        }
    }
    return v;
}

int main() {
    int n;
    cin >> n;
    auto v = sieve();
    int ans = 0;
    rep(i, n + 1) {
        if (v[i] == 1) continue;
        ans += i;
    }
    out(ans);
}
0