結果

問題 No.36 素数が嫌い!
ユーザー frozenlibfrozenlib
提出日時 2018-06-15 16:44:49
言語 Rust
(1.77.0)
結果
AC  
実行時間 95 ms / 5,000 ms
コード長 1,528 bytes
コンパイル時間 12,069 ms
コンパイル使用メモリ 406,980 KB
実行使用メモリ 17,992 KB
最終ジャッジ日時 2024-06-30 14:50:13
合計ジャッジ時間 14,341 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
8,712 KB
testcase_01 AC 61 ms
13,308 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 1 ms
6,940 KB
testcase_06 AC 1 ms
6,944 KB
testcase_07 AC 1 ms
6,940 KB
testcase_08 AC 1 ms
6,940 KB
testcase_09 AC 1 ms
6,940 KB
testcase_10 AC 1 ms
6,940 KB
testcase_11 AC 27 ms
6,944 KB
testcase_12 AC 94 ms
16,500 KB
testcase_13 AC 93 ms
17,924 KB
testcase_14 AC 47 ms
10,952 KB
testcase_15 AC 1 ms
6,940 KB
testcase_16 AC 0 ms
6,940 KB
testcase_17 AC 1 ms
6,944 KB
testcase_18 AC 1 ms
6,944 KB
testcase_19 AC 29 ms
7,620 KB
testcase_20 AC 85 ms
17,992 KB
testcase_21 AC 59 ms
13,008 KB
testcase_22 AC 60 ms
13,308 KB
testcase_23 AC 36 ms
8,820 KB
testcase_24 AC 40 ms
9,596 KB
testcase_25 AC 38 ms
9,332 KB
testcase_26 AC 54 ms
10,744 KB
testcase_27 AC 77 ms
14,292 KB
testcase_28 AC 52 ms
10,680 KB
testcase_29 AC 95 ms
15,876 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];
    let mut ps = Vec::new();
    for i in 2..np.len() {
        if !np[i] {
            let mut j = i * 2;
            while j < np.len() {
                np[j] = true;
                j += i;
            }
            ps.push(i);
        }
    }
    for &p in &ps {
        if n % p == 0 {
            let nd = n / p;
            for &p in &ps {
                if nd % p == 0 && nd / p > 1 {
                    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