結果
| 問題 | No.843 Triple Primes | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2022-12-01 02:14:21 | 
| 言語 | Rust (1.83.0 + proconio) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 5 ms / 2,000 ms | 
| コード長 | 867 bytes | 
| コンパイル時間 | 11,719 ms | 
| コンパイル使用メモリ | 393,928 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-10-07 22:12:06 | 
| 合計ジャッジ時間 | 13,415 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 42 | 
ソースコード
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();
    if n == 1 {
        println!("0");
        return;
    }
    let primes = get_primes(n);
    let mut result = 0usize;
    for q in 2..=n {
        if !primes[q] { continue; }
        let r = ((2 + q) as f64).sqrt().floor() as usize;
        if r * r == 2 + q && primes[r] {
            result += 1;
        }
    }
    if result == 0 {
        println!("0");
        return;
    } else {
        println!("{}", result * 2 - 1);
    }
}
            
            
            
        