結果

問題 No.36 素数が嫌い!
ユーザー frozenlibfrozenlib
提出日時 2018-06-15 16:44:49
言語 Rust
(1.77.0)
結果
AC  
実行時間 110 ms / 5,000 ms
コード長 1,528 bytes
コンパイル時間 643 ms
コンパイル使用メモリ 146,652 KB
実行使用メモリ 16,408 KB
最終ジャッジ日時 2023-09-13 04:37:09
合計ジャッジ時間 3,280 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
8,720 KB
testcase_01 AC 71 ms
13,324 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 27 ms
6,660 KB
testcase_12 AC 104 ms
16,408 KB
testcase_13 AC 104 ms
16,296 KB
testcase_14 AC 48 ms
11,036 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 31 ms
7,812 KB
testcase_20 AC 93 ms
16,400 KB
testcase_21 AC 63 ms
13,124 KB
testcase_22 AC 71 ms
13,364 KB
testcase_23 AC 36 ms
8,852 KB
testcase_24 AC 43 ms
9,564 KB
testcase_25 AC 41 ms
9,544 KB
testcase_26 AC 56 ms
10,908 KB
testcase_27 AC 88 ms
14,284 KB
testcase_28 AC 52 ms
10,548 KB
testcase_29 AC 110 ms
15,824 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