結果
| 問題 | No.843 Triple Primes | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2022-12-01 02:10:06 | 
| 言語 | Rust (1.83.0 + proconio) | 
| 結果 | 
                                RE
                                 
                             | 
| 実行時間 | - | 
| コード長 | 725 bytes | 
| コンパイル時間 | 14,443 ms | 
| コンパイル使用メモリ | 380,220 KB | 
| 実行使用メモリ | 6,824 KB | 
| 最終ジャッジ日時 | 2024-10-07 22:04:54 | 
| 合計ジャッジ時間 | 16,226 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 36 WA * 4 RE * 2 | 
ソースコード
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);
}
            
            
            
        