結果
問題 | No.106 素数が嫌い!2 |
ユーザー | aimy |
提出日時 | 2017-10-21 13:25:45 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 661 ms / 5,000 ms |
コード長 | 2,523 bytes |
コンパイル時間 | 13,900 ms |
コンパイル使用メモリ | 377,384 KB |
実行使用メモリ | 19,136 KB |
最終ジャッジ日時 | 2024-11-21 12:29:44 |
合計ジャッジ時間 | 17,567 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 252 ms
10,752 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 | 252 ms
10,752 KB |
testcase_05 | AC | 658 ms
19,064 KB |
testcase_06 | AC | 659 ms
19,072 KB |
testcase_07 | AC | 661 ms
19,136 KB |
testcase_08 | AC | 18 ms
5,248 KB |
testcase_09 | AC | 20 ms
5,248 KB |
testcase_10 | AC | 660 ms
19,128 KB |
testcase_11 | AC | 215 ms
9,700 KB |
testcase_12 | AC | 623 ms
18,424 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 |
ソースコード
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); } 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() } #[allow(dead_code)] fn factorize(n: usize, ps: &[usize]) -> Vec<usize> { let mut fs = vec![]; let mut x = n; for &p in ps { 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 } }