結果
| 問題 |
No.36 素数が嫌い!
|
| コンテスト | |
| ユーザー |
sino
|
| 提出日時 | 2020-04-13 11:00:10 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,682 bytes |
| コンパイル時間 | 11,038 ms |
| コンパイル使用メモリ | 403,712 KB |
| 実行使用メモリ | 18,204 KB |
| 最終ジャッジ日時 | 2024-09-24 15:17:53 |
| 合計ジャッジ時間 | 12,831 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 21 WA * 5 |
ソースコード
#![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()
}
sino