結果

問題 No.36 素数が嫌い!
ユーザー sinosino
提出日時 2020-04-13 11:00:10
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 1,682 bytes
コンパイル時間 4,845 ms
コンパイル使用メモリ 166,948 KB
実行使用メモリ 17,832 KB
最終ジャッジ日時 2023-10-24 20:18:51
合計ジャッジ時間 6,050 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
8,672 KB
testcase_01 AC 51 ms
13,228 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 0 ms
4,348 KB
testcase_04 AC 0 ms
4,348 KB
testcase_05 WA -
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 20 ms
6,608 KB
testcase_12 AC 67 ms
17,832 KB
testcase_13 AC 66 ms
17,804 KB
testcase_14 AC 41 ms
10,944 KB
testcase_15 AC 1 ms
4,348 KB
testcase_16 AC 1 ms
4,348 KB
testcase_17 AC 1 ms
4,348 KB
testcase_18 AC 1 ms
4,348 KB
testcase_19 AC 25 ms
7,712 KB
testcase_20 AC 64 ms
17,804 KB
testcase_21 AC 49 ms
13,084 KB
testcase_22 AC 52 ms
13,308 KB
testcase_23 AC 32 ms
8,752 KB
testcase_24 AC 33 ms
9,524 KB
testcase_25 AC 32 ms
9,440 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::collections::HashMap;
use std::collections::HashSet;

#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($t:ty) =>
        (rl().parse::<$t>().unwrap());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    buf.trim_end().to_owned()
}

fn main() {
    let n = read!(u64);

    let sqrtn = (n as f64).sqrt() as usize;
    let primes = primes(sqrtn);

    let num = primes
        .into_iter()
        .enumerate()
        .skip(1)
        .filter(|(i, _)| n % (*i as u64) == 0)
        .count();

    if num >= 2 {
        println!("YES");
    }
    else {
        println!("NO");
    }
}

fn primes(n: usize) -> Vec::<usize> {
    if n < 2 {
        return vec![];
    }

    let mut table = vec![true; n+1];
    table[0] = false;
    table[1] = false;

    for i in 2..=(n as f64).sqrt() as usize {
        if table[i] == false {
            continue;
        }

        let mut j = i*i;
        while j <= n {
            table[j] = false;
            j += i;
        }
    }

    table
        .iter()
        .enumerate()
        .filter(|(_, &flg)| flg)
        .map(|(num, _)| num)
        .collect()
}
0