結果

問題 No.1657 Sum is Prime (Easy Version)
ユーザー ぷらぷら
提出日時 2021-08-27 21:26:55
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 916 bytes
コンパイル時間 2,146 ms
コンパイル使用メモリ 202,840 KB
実行使用メモリ 11,164 KB
最終ジャッジ日時 2024-05-01 01:36:04
合計ジャッジ時間 3,429 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 16 ms
11,012 KB
testcase_02 AC 18 ms
10,988 KB
testcase_03 WA -
testcase_04 AC 16 ms
10,996 KB
testcase_05 AC 15 ms
11,144 KB
testcase_06 AC 15 ms
10,996 KB
testcase_07 AC 15 ms
11,028 KB
testcase_08 AC 17 ms
11,000 KB
testcase_09 AC 15 ms
11,164 KB
testcase_10 AC 16 ms
10,976 KB
testcase_11 AC 18 ms
10,984 KB
testcase_12 AC 18 ms
11,012 KB
testcase_13 AC 16 ms
11,116 KB
testcase_14 AC 16 ms
11,092 KB
testcase_15 AC 17 ms
11,008 KB
testcase_16 AC 16 ms
11,056 KB
testcase_17 AC 15 ms
11,032 KB
testcase_18 AC 15 ms
11,004 KB
testcase_19 AC 21 ms
11,060 KB
testcase_20 AC 16 ms
10,988 KB
testcase_21 WA -
testcase_22 AC 16 ms
11,024 KB
testcase_23 AC 16 ms
10,972 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

struct primenumber {
    vector<int> spf;
    primenumber(int N) {
        init(N);
    }
    void init(int N) {
        spf.assign(N+1,0);
        for(int i = 0; i <= N; i++) {
            spf[i] = i;
        }
        for(int i = 2; i*i <= N; i++) {
            if(spf[i] == i) {
                for(int j = i*i; j <= N; j += i) {
                    if(spf[j] == j) {
                        spf[j] = i;
                    }
                }
            }
        }
    }
    int get(int n) {
        if(spf[n] == n) {
            return 1;
        }
        return 0;
    }
};

int main() {
    int L,R;
    cin >> L >> R;
    primenumber zz(2000001);
    int ans = 0;
    for(int i = L; i <= R; i++) {
        if(zz.get(i) == 1) {
            ans++;
        }
        if(i+1 <= R && zz.get(i+i+1)) {
            ans++;
        }
    }
    cout << ans << endl;
}
0