結果
問題 | No.106 素数が嫌い!2 |
ユーザー | aimy |
提出日時 | 2017-10-21 12:46:57 |
言語 | Rust (1.77.0 + proconio) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,587 bytes |
コンパイル時間 | 14,373 ms |
コンパイル使用メモリ | 390,936 KB |
実行使用メモリ | 15,952 KB |
最終ジャッジ日時 | 2024-11-21 12:29:22 |
合計ジャッジ時間 | 81,532 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | TLE | - |
testcase_01 | AC | 1 ms
10,144 KB |
testcase_02 | AC | 1 ms
10,276 KB |
testcase_03 | AC | 1 ms
9,124 KB |
testcase_04 | TLE | - |
testcase_05 | TLE | - |
testcase_06 | TLE | - |
testcase_07 | TLE | - |
testcase_08 | TLE | - |
testcase_09 | TLE | - |
testcase_10 | TLE | - |
testcase_11 | TLE | - |
testcase_12 | TLE | - |
testcase_13 | AC | 1 ms
6,816 KB |
testcase_14 | AC | 1 ms
6,816 KB |
testcase_15 | AC | 13 ms
11,040 KB |
ソースコード
fn main() { let (n, k): (usize, usize) = get::tuple(); let mut ns: Vec<bool> = vec![false; n+1]; let valid = |x| { let mut fs = factorize(x); fs.dedup(); fs.len() >= k }; for i in 2 .. n+1 { if ns[i] {continue} if valid(i) { for d in 1 .. n/i + 1 {ns[i*d] = true} } } let ans = ns.iter().filter(|&&p|p).count(); println!("{}", ans); } fn is_prime(n: usize) -> bool { let sq = (n as f64).sqrt().floor() as usize; let p = (2..sq+1).all(|d| n%d != 0); p } fn primes(n: usize) -> Vec<usize> { (2..n+1).filter(|&x|is_prime(x)).collect() } fn factorize(n: usize) -> Vec<usize> { let mut fs = vec![]; let mut x = n; for p in primes(n) { while x > 1 && x % p == 0 { fs.push(p); x /= p; } } fs } #[allow(dead_code)] mod get { use std::io::*; use std::str::*; pub fn val<T: FromStr>() -> T { let mut buf = String::new(); stdin().read_line(&mut buf).ok(); buf.trim().parse::<T>().ok().unwrap() } pub fn vals<T: FromStr>(n: usize) -> Vec<T> { let mut vec: Vec<T> = vec![]; for _ in 0 .. n { vec.push(val()); } vec } pub fn tuple<T1: FromStr, T2: FromStr>() -> (T1, T2) { let mut buf = String::new(); stdin().read_line(&mut buf).ok(); let mut it = buf.trim().split_whitespace(); let x = it.next().unwrap().parse::<T1>().ok().unwrap(); let y = it.next().unwrap().parse::<T2>().ok().unwrap(); (x, y) } pub fn tuples<T1: FromStr, T2: FromStr>(n: usize) -> Vec<(T1, T2)> { let mut vec: Vec<(T1, T2)> = vec![]; for _ in 0 .. n { vec.push(tuple()); } vec } pub fn tuple3<T1: FromStr, T2: FromStr, T3: FromStr>() -> (T1, T2, T3) { let mut buf = String::new(); stdin().read_line(&mut buf).ok(); let mut it = buf.trim().split_whitespace(); let x = it.next().unwrap().parse::<T1>().ok().unwrap(); let y = it.next().unwrap().parse::<T2>().ok().unwrap(); let z = it.next().unwrap().parse::<T3>().ok().unwrap(); (x, y, z) } pub fn tuple3s<T1: FromStr, T2: FromStr, T3: FromStr>(n: usize) -> Vec<(T1, T2, T3)> { let mut vec: Vec<(T1, T2, T3)> = vec![]; for _ in 0 .. n { vec.push(tuple3()); } vec } pub fn list<T: FromStr>() -> Vec<T> { let mut buf = String::new(); stdin().read_line(&mut buf).ok(); buf.trim().split_whitespace().map(|t| t.parse::<T>().ok().unwrap()).collect() } pub fn lists<T: FromStr>(h: usize) -> Vec<Vec<T>> { let mut mat: Vec<Vec<T>> = vec![]; for _ in 0 .. h { mat.push(list()); } mat } }