Submission #54072242
Source Code Expand
#![allow(unused)]
// [Problem]
// Please find the number of integers between 2 and N (inclusive) that have at least K distinct prime factors.
// [Solution]
// Variant of Sieve of Eratosthenes
// cnt[i] = number of prime factors of i
fn main() {
let inp = readv::<usize>();
let (n, k) = (inp[0], inp[1]);
let mut cnt = vec![0; n + 1];
for i in 2..=n {
if cnt[i] == 0 {
for j in (i..=n).step_by(i) {
cnt[j] += 1;
}
}
}
let mut ans = 0;
for i in 2..=n {
if cnt[i] >= k {
ans += 1;
}
}
println!("{}", ans);
}
fn read<T: std::str::FromStr>() -> T {
let mut s = String::new();
std::io::stdin().read_line(&mut s).ok();
s.trim().parse().ok().unwrap()
}
fn readv<T: std::str::FromStr>() -> Vec<T> {
read::<String>()
.split_ascii_whitespace()
.map(|t| t.parse().ok().unwrap())
.collect()
}
fn reads() -> Vec<char> {
read::<String>().chars().collect::<Vec<char>>()
}
fn mapv<T, S, F: Fn(&T) -> S>(arr: &Vec<T>, f: F) -> Vec<S> {
arr.iter().map(f).collect()
}
fn join<T: ToString>(arr: &[T], sep: &str) -> String {
arr.iter()
.map(|x| x.to_string())
.collect::<Vec<String>>()
.join(sep)
}
Submission Info
| Submission Time | |
|---|---|
| Task | 030 - K Factors(★5) |
| User | amoshuangyc |
| Language | Rust (rustc 1.70.0) |
| Score | 5 |
| Code Size | 1341 Byte |
| Status | AC |
| Exec Time | 275 ms |
| Memory | 79976 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 5 / 5 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt, sample_05.txt |
| All | 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 02_large_01.txt, 02_large_02.txt, 02_large_03.txt, 02_large_04.txt, 02_large_05.txt, 02_large_06.txt, 02_large_07.txt, 02_large_08.txt, 02_large_09.txt, 02_large_10.txt, sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt, sample_05.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 01_random_01.txt | AC | 52 ms | 25560 KiB |
| 01_random_02.txt | AC | 32 ms | 18188 KiB |
| 01_random_03.txt | AC | 84 ms | 33708 KiB |
| 01_random_04.txt | AC | 1 ms | 1996 KiB |
| 01_random_05.txt | AC | 8 ms | 6544 KiB |
| 01_random_06.txt | AC | 47 ms | 24288 KiB |
| 01_random_07.txt | AC | 100 ms | 36460 KiB |
| 01_random_08.txt | AC | 181 ms | 57896 KiB |
| 01_random_09.txt | AC | 4 ms | 3728 KiB |
| 01_random_10.txt | AC | 80 ms | 33992 KiB |
| 01_random_11.txt | AC | 13 ms | 9424 KiB |
| 01_random_12.txt | AC | 75 ms | 31540 KiB |
| 01_random_13.txt | AC | 15 ms | 10172 KiB |
| 01_random_14.txt | AC | 49 ms | 25540 KiB |
| 01_random_15.txt | AC | 208 ms | 64412 KiB |
| 02_large_01.txt | AC | 256 ms | 74848 KiB |
| 02_large_02.txt | AC | 139 ms | 46416 KiB |
| 02_large_03.txt | AC | 243 ms | 72088 KiB |
| 02_large_04.txt | AC | 170 ms | 54892 KiB |
| 02_large_05.txt | AC | 179 ms | 55956 KiB |
| 02_large_06.txt | AC | 258 ms | 75672 KiB |
| 02_large_07.txt | AC | 158 ms | 50888 KiB |
| 02_large_08.txt | AC | 273 ms | 79976 KiB |
| 02_large_09.txt | AC | 273 ms | 79900 KiB |
| 02_large_10.txt | AC | 275 ms | 79960 KiB |
| sample_01.txt | AC | 0 ms | 1956 KiB |
| sample_02.txt | AC | 1 ms | 1900 KiB |
| sample_03.txt | AC | 0 ms | 1908 KiB |
| sample_04.txt | AC | 11 ms | 8596 KiB |
| sample_05.txt | AC | 275 ms | 79960 KiB |