結果

問題 No.843 Triple Primes
ユーザー phsplsphspls
提出日時 2022-12-01 02:10:06
言語 Rust
(1.77.0)
結果
RE  
実行時間 -
コード長 725 bytes
コンパイル時間 1,238 ms
コンパイル使用メモリ 146,760 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-16 19:57:25
合計ジャッジ時間 2,661 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 4 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 4 ms
5,376 KB
testcase_08 AC 4 ms
5,376 KB
testcase_09 AC 5 ms
5,376 KB
testcase_10 AC 4 ms
5,376 KB
testcase_11 AC 4 ms
5,376 KB
testcase_12 AC 4 ms
5,376 KB
testcase_13 AC 5 ms
5,376 KB
testcase_14 AC 4 ms
5,376 KB
testcase_15 AC 4 ms
5,376 KB
testcase_16 AC 4 ms
5,376 KB
testcase_17 RE -
testcase_18 WA -
testcase_19 AC 1 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 3 ms
5,376 KB
testcase_23 AC 3 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 1 ms
5,376 KB
testcase_26 AC 5 ms
5,376 KB
testcase_27 AC 1 ms
5,376 KB
testcase_28 AC 4 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
testcase_30 AC 4 ms
5,376 KB
testcase_31 AC 1 ms
5,376 KB
testcase_32 AC 1 ms
5,376 KB
testcase_33 AC 2 ms
5,376 KB
testcase_34 AC 3 ms
5,376 KB
testcase_35 AC 5 ms
5,376 KB
testcase_36 AC 2 ms
5,376 KB
testcase_37 AC 4 ms
5,376 KB
testcase_38 AC 3 ms
5,376 KB
testcase_39 AC 4 ms
5,376 KB
testcase_40 WA -
testcase_41 RE -
testcase_42 WA -
testcase_43 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

fn get_primes(n: usize) -> Vec<bool> {
    let mut flgs = vec![true; n+1];
    flgs[0] = false;
    flgs[1] = false;

    for i in 2..=(n as f64).sqrt().ceil() as usize {
        if !flgs[i] { continue; }
        for j in i..=n/i {
            flgs[i*j] = false;
        }
    }

    flgs
}

fn main() {
    let mut n = String::new();
    std::io::stdin().read_line(&mut n).ok();
    let n: usize = n.trim().parse().unwrap();

    let primes = get_primes(n);
    let mut result = 0usize;
    for q in 2..=n-2 {
        if !primes[q] { continue; }
        let r = ((2 + q) as f64).sqrt().floor() as usize;
        if r * r == 2 + q && primes[r] {
            result += 1;
        }
    }
    println!("{}", result * 2 - 1);
}
0