結果

問題 No.843 Triple Primes
ユーザー tactac
提出日時 2019-07-09 01:32:24
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 506 ms / 2,000 ms
コード長 1,053 bytes
コンパイル時間 1,491 ms
コンパイル使用メモリ 168,272 KB
実行使用メモリ 32,024 KB
最終ジャッジ日時 2023-10-19 18:05:31
合計ジャッジ時間 22,588 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 440 ms
32,024 KB
testcase_01 AC 436 ms
32,024 KB
testcase_02 AC 438 ms
32,024 KB
testcase_03 AC 414 ms
32,024 KB
testcase_04 AC 475 ms
32,024 KB
testcase_05 AC 462 ms
32,024 KB
testcase_06 AC 472 ms
32,024 KB
testcase_07 AC 469 ms
32,024 KB
testcase_08 AC 441 ms
32,024 KB
testcase_09 AC 443 ms
32,024 KB
testcase_10 AC 476 ms
32,024 KB
testcase_11 AC 506 ms
32,024 KB
testcase_12 AC 478 ms
32,024 KB
testcase_13 AC 438 ms
32,024 KB
testcase_14 AC 441 ms
32,024 KB
testcase_15 AC 418 ms
32,024 KB
testcase_16 AC 445 ms
32,024 KB
testcase_17 AC 444 ms
32,024 KB
testcase_18 AC 442 ms
32,024 KB
testcase_19 AC 383 ms
32,024 KB
testcase_20 AC 394 ms
32,024 KB
testcase_21 AC 404 ms
32,024 KB
testcase_22 AC 379 ms
32,024 KB
testcase_23 AC 427 ms
32,024 KB
testcase_24 AC 442 ms
32,024 KB
testcase_25 AC 447 ms
32,024 KB
testcase_26 AC 417 ms
32,024 KB
testcase_27 AC 405 ms
32,024 KB
testcase_28 AC 453 ms
32,024 KB
testcase_29 AC 454 ms
32,024 KB
testcase_30 AC 437 ms
32,024 KB
testcase_31 AC 460 ms
32,024 KB
testcase_32 AC 473 ms
32,024 KB
testcase_33 AC 411 ms
32,024 KB
testcase_34 AC 454 ms
32,024 KB
testcase_35 AC 438 ms
32,024 KB
testcase_36 AC 407 ms
32,024 KB
testcase_37 AC 459 ms
32,024 KB
testcase_38 AC 485 ms
32,024 KB
testcase_39 AC 448 ms
32,024 KB
testcase_40 AC 435 ms
32,024 KB
testcase_41 AC 453 ms
32,024 KB
testcase_42 AC 437 ms
32,024 KB
testcase_43 AC 455 ms
32,024 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 = max(a, b)
#define chmin(a, b) a = min(a, b)
#define out(a) cout << a << endl
#define SZ(v) (int)v.size()

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;
    vector<int> v = sieve();
    int cnt = 0;
    //1つを2に固定
    rep3(r, 2, n + 1) {
        if (v[r] == 1) continue;
        if ((ll)r * r - 2 > n) break;
        int p = r * r - 2;
        if (v[p] == 1) continue;
        //out(2 << " " << p << " " << r);
        if (p == 2) cnt++;
        else cnt += 2;
    }
    out(cnt);
}
0