結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 17 ms
4,384 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 17 ms
5,212 KB
testcase_13 AC 8 ms
4,376 KB
testcase_14 AC 13 ms
4,924 KB
testcase_15 AC 13 ms
4,888 KB
testcase_16 AC 6 ms
4,384 KB
testcase_17 AC 6 ms
4,376 KB
testcase_18 AC 6 ms
4,376 KB
testcase_19 AC 16 ms
4,384 KB
testcase_20 AC 9 ms
4,628 KB
testcase_21 AC 18 ms
5,416 KB
testcase_22 AC 14 ms
5,484 KB
testcase_23 AC 14 ms
5,152 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) {
        if (sieve[i]) ++res;
        if (sieve[i*2+1]) ++res;
    }

    if (sieve[R]) ++res;

    res.writeln;
}
0