結果

問題 No.36 素数が嫌い!
ユーザー frozenlibfrozenlib
提出日時 2018-06-15 13:32:21
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 1,577 bytes
コンパイル時間 581 ms
コンパイル使用メモリ 146,152 KB
実行使用メモリ 18,184 KB
最終ジャッジ日時 2023-09-13 04:35:04
合計ジャッジ時間 2,965 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
8,776 KB
testcase_01 AC 80 ms
13,244 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 WA -
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 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 32 ms
6,660 KB
testcase_12 AC 105 ms
17,632 KB
testcase_13 WA -
testcase_14 AC 56 ms
11,052 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 35 ms
7,808 KB
testcase_20 AC 100 ms
16,400 KB
testcase_21 AC 70 ms
13,176 KB
testcase_22 AC 73 ms
13,408 KB
testcase_23 AC 44 ms
8,868 KB
testcase_24 AC 50 ms
9,616 KB
testcase_25 AC 48 ms
9,456 KB
testcase_26 AC 63 ms
10,864 KB
testcase_27 AC 93 ms
14,256 KB
testcase_28 AC 62 ms
10,448 KB
testcase_29 AC 111 ms
15,816 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io::*;
use std::str::FromStr;
use utils::*;

pub fn main() {
    let i = stdin();
    let mut o = Vec::new();
    run(i.lock(), &mut o);
    stdout().write_all(&o).unwrap();
}

fn run<R: BufRead, W: Write>(i: R, o: &mut W) {
    let mut i = CpReader::new(i);
    let n = i.read::<usize>();
    let r = if solve(n) { "YES" } else { "NO" };
    writeln!(o, "{}", r).unwrap();
}
fn solve(n: usize) -> bool {
    let mut np = vec![false; (n as f64).sqrt() as usize + 1];
    for i in 2..np.len() {
        if !np[i] {
            let mut j = i * 2;
            while j < np.len() {
                np[j] = true;
                j += i;
            }
        }
    }
    let mut ps = Vec::new();
    for i in 2..np.len() {
        if !np[i] {
            ps.push(i);
        }
    }
    for &p in &ps {
        if n % p == 0 {
            let nd = n / p;
            for &p in &ps {
                if nd % p == 0 {
                    return true;
                }
            }
        }
    }
    false
}

mod utils {
    use super::*;

    pub struct CpReader<R: BufRead> {
        r: R,
        s: String,
    }
    impl<R: BufRead> CpReader<R> {
        pub fn new(r: R) -> Self {
            CpReader {
                r: r,
                s: String::new(),
            }
        }
        pub fn read_line(&mut self) -> &str {
            self.s.clear();
            self.r.read_line(&mut self.s).unwrap();
            self.s.trim()
        }

        pub fn read<T: FromStr>(&mut self) -> T {
            self.read_line().parse().ok().unwrap()
        }
    }
}
0