Hello codeforces!
I have a problem: counting primes in $$$[m, n)$$$ where $$$1<=m<n<=2 \cdot 10^9$$$.
Because the range could be large, I can't use sieve because of the memory complexity or normal primality test in $$$O(sqrt(n))$$$
Thanks very much!
# | User | Rating |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3773 |
3 | Radewoosh | 3646 |
4 | ecnerwala | 3624 |
5 | jqdai0815 | 3620 |
5 | Benq | 3620 |
7 | orzdevinwang | 3612 |
8 | Geothermal | 3569 |
8 | cnnfls_csy | 3569 |
10 | gyh20 | 3447 |
# | User | Contrib. |
---|---|---|
1 | awoo | 161 |
2 | maomao90 | 160 |
2 | cry | 160 |
4 | nor | 156 |
4 | atcoder_official | 156 |
6 | -is-this-fft- | 155 |
7 | adamant | 153 |
7 | maroonrk | 153 |
9 | Um_nik | 152 |
10 | djm03178 | 146 |
Hello codeforces!
I have a problem: counting primes in $$$[m, n)$$$ where $$$1<=m<n<=2 \cdot 10^9$$$.
Because the range could be large, I can't use sieve because of the memory complexity or normal primality test in $$$O(sqrt(n))$$$
Thanks very much!
Name |
---|
Check again your problem, may be you can sieve on range?
We call
P(i) = the number of primes <= i
The answer for the problem is
P(N - 1) - P(M - 1)
since N <= 2 * 10^9, we can preprocess 2000 integers where the i-th one shows P(i * 10^6)
The leftover length is not bigger than 10^6 so you can sieve on that range, it should pass the time limit.
How to use sieve on range [l,r], where l is very big? Don't we have to know all primes before l to apply sieve?
https://mirror.codeforces.com/blog/entry/91632 Certainly covers your problem