結果
問題 | No.106 素数が嫌い!2 |
ユーザー | aimy |
提出日時 | 2017-10-24 09:32:33 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 48 ms / 5,000 ms |
コード長 | 2,912 bytes |
コンパイル時間 | 12,353 ms |
コンパイル使用メモリ | 390,248 KB |
実行使用メモリ | 18,756 KB |
最終ジャッジ日時 | 2024-11-21 17:34:12 |
合計ジャッジ時間 | 13,827 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 19 ms
10,396 KB |
testcase_01 | AC | 1 ms
5,248 KB |
testcase_02 | AC | 1 ms
5,248 KB |
testcase_03 | AC | 1 ms
5,248 KB |
testcase_04 | AC | 18 ms
10,380 KB |
testcase_05 | AC | 44 ms
18,736 KB |
testcase_06 | AC | 41 ms
18,672 KB |
testcase_07 | AC | 44 ms
18,756 KB |
testcase_08 | AC | 3 ms
5,248 KB |
testcase_09 | AC | 3 ms
5,248 KB |
testcase_10 | AC | 48 ms
18,624 KB |
testcase_11 | AC | 16 ms
9,308 KB |
testcase_12 | AC | 42 ms
18,076 KB |
testcase_13 | AC | 1 ms
5,248 KB |
testcase_14 | AC | 1 ms
5,248 KB |
testcase_15 | AC | 1 ms
5,248 KB |
ソースコード
use prime::*; fn main() { let (n, k): (usize, usize) = get::tuple(); let ps = primes(n); let mut ns: Vec<usize> = vec![0; n+1]; for p in ps { for i in (1..).map(|x|x*p).take_while(|&x|x<=n) { ns[i] += 1 } } let ans = ns.iter().filter(|&&p|p>=k).count(); println!("{}", ans); } #[allow(dead_code)] mod prime { pub 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 } pub fn primes(n: usize) -> Vec<usize> { let mut ps = vec![true; n+1]; ps[0] = false; ps[1] = false; for i in 2 .. n+1 { if ps[i] { for k in 2 .. n/i+1 { ps[i*k] = false; } } } ps.iter().enumerate().filter(|&(_,&p)|p).map(|(i,_)|i).collect() } pub fn factorize(n: usize) -> Vec<usize> { let sq = (n as f64).sqrt().floor() as usize; let mut fs = vec![]; let mut x = n; for d in 2 .. sq+1 { if x == 1 {break} while x > 1 && x % d == 0 { fs.push(d); x /= d; } } if x != 1 {fs.push(x)}; 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 } }