Submission #30209717
Source Code Expand
use proconio::input;
fn main() {
input! {
l: usize,
r: usize,
};
let n = 1_000_000;
let mut ps = vec![];
let mut b1 = vec![true; n + 1];
b1[0] = false;
b1[1] = false;
for i in 2.. {
if i * i > n {
for j in i..=n {
if b1[j] {
ps.push(j);
}
}
break;
}
if b1[i] {
ps.push(i);
for j in (i + i..=n).step_by(i) {
b1[j] = false;
}
}
}
// 2 3 5
// 0 1 2 3 4 5 6
// [5 6]
// 2: 0 1 0 1 0 1 0
// 3: 0 1 2 0 1 2 0
// 5: 0 1 2 3 4 0 1
//
let mut b2 = vec![true; r - l + 1];
for p in ps.iter().copied() {
let o = (p - (l % p)) % p;
for q in (o..r - l + 1).step_by(p) {
b2[q] = false;
}
}
for (i, b2_i) in b2.iter_mut().enumerate() {
if l + i <= 1_000_000 {
*b2_i = b1[l + i];
}
}
let ans = b2.into_iter().filter(|b| *b).count();
println!("{}", ans);
}
Submission Info
| Submission Time | |
|---|---|
| Task | 097 - Primes in an Interval |
| User | bouzuya |
| Language | Rust (1.42.0) |
| Score | 1000 |
| Code Size | 1111 Byte |
| Status | AC |
| Exec Time | 27 ms |
| Memory | 4260 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 1000 / 1000 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt, sample_05.txt |
| All | in01.txt, in02.txt, in03.txt, in04.txt, in05.txt, in06.txt, in07.txt, in08.txt, in09.txt, in10.txt, in11.txt, in12.txt, in13.txt, in14.txt, in15.txt, sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt, sample_05.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| in01.txt | AC | 26 ms | 3600 KiB |
| in02.txt | AC | 18 ms | 3460 KiB |
| in03.txt | AC | 21 ms | 3576 KiB |
| in04.txt | AC | 20 ms | 3672 KiB |
| in05.txt | AC | 23 ms | 4260 KiB |
| in06.txt | AC | 19 ms | 3616 KiB |
| in07.txt | AC | 23 ms | 3516 KiB |
| in08.txt | AC | 22 ms | 3596 KiB |
| in09.txt | AC | 27 ms | 3884 KiB |
| in10.txt | AC | 21 ms | 3920 KiB |
| in11.txt | AC | 21 ms | 3912 KiB |
| in12.txt | AC | 21 ms | 4200 KiB |
| in13.txt | AC | 22 ms | 4132 KiB |
| in14.txt | AC | 21 ms | 4096 KiB |
| in15.txt | AC | 22 ms | 4148 KiB |
| sample_01.txt | AC | 23 ms | 3704 KiB |
| sample_02.txt | AC | 21 ms | 3512 KiB |
| sample_03.txt | AC | 21 ms | 3660 KiB |
| sample_04.txt | AC | 21 ms | 3644 KiB |
| sample_05.txt | AC | 23 ms | 4104 KiB |