結果

問題 No.1657 Sum is Prime (Easy Version)
ユーザー kokatsukokatsu
提出日時 2022-11-20 21:33:12
言語 D
(dmd 2.106.1)
結果
WA  
実行時間 -
コード長 469 bytes
コンパイル時間 3,118 ms
コンパイル使用メモリ 200,364 KB
実行使用メモリ 5,532 KB
最終ジャッジ日時 2023-09-04 18:59:43
合計ジャッジ時間 4,586 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 17 ms
5,532 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 2 ms
4,380 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 2 ms
4,376 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 17 ms
5,172 KB
testcase_13 AC 9 ms
4,384 KB
testcase_14 AC 13 ms
4,872 KB
testcase_15 AC 14 ms
4,836 KB
testcase_16 AC 6 ms
4,376 KB
testcase_17 AC 6 ms
4,380 KB
testcase_18 AC 6 ms
4,380 KB
testcase_19 AC 16 ms
5,176 KB
testcase_20 AC 9 ms
4,580 KB
testcase_21 AC 18 ms
5,440 KB
testcase_22 AC 15 ms
5,388 KB
testcase_23 AC 15 ms
5,176 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std;

void main() {
    int L, R;
    readf("%d %d\n", L, R);

    int N = R * 2 + 10;
    auto sieve = new bool[](N+1);
    sieve[2..N+1] = true;
    int d = 2;
    while (d * d <= N) {
        if (sieve[d]) {
            foreach (i; iota(d*d, N+1, d)) {
                sieve[i] = false;
            }
        }
        ++d;
    }

    int res;
    foreach (i; L .. R+1) {
        if (sieve[i]) ++res;
        if (sieve[i*2+1]) ++res;
    }

    res.writeln;
}
0