mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-27 17:56:28 +00:00
P1835 素数密度
R67087367
This commit is contained in:
parent
3bc27c14ff
commit
0c113b8ee7
36
Luogu/P1835/P1835.cpp
Normal file
36
Luogu/P1835/P1835.cpp
Normal file
@ -0,0 +1,36 @@
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
|
||||
using std::cin;
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
|
||||
const int N = 1000005;
|
||||
|
||||
long long l, r, cnt, primes[N], ans;
|
||||
bool vis[N];
|
||||
|
||||
int main() {
|
||||
for (int i = 2; i <= 1000000; i++) {
|
||||
if (!vis[i]) {
|
||||
primes[++cnt] = i;
|
||||
for (int j = i; j <= 1000000; j += i) {
|
||||
vis[j] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
cin >> l >> r;
|
||||
memset(vis, 0x00, sizeof(vis));
|
||||
l = std::max(l, 2ll);
|
||||
for (int i = 1; i <= cnt; i++) {
|
||||
long long p = primes[i];
|
||||
for (long long j = std::max((l + p - 1) / p * p, p * 2); j <= r; j += p) {
|
||||
vis[j - l + 1] = true;
|
||||
}
|
||||
}
|
||||
for (int i = 1; i <= r - l + 1; i++) {
|
||||
if (!vis[i]) ans++;
|
||||
}
|
||||
cout << ans << endl;
|
||||
return 0;
|
||||
}
|
BIN
Luogu/P1835/data/P1835_6.in
(Stored with Git LFS)
Normal file
BIN
Luogu/P1835/data/P1835_6.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P1835/data/P1835_6.out
(Stored with Git LFS)
Normal file
BIN
Luogu/P1835/data/P1835_6.out
(Stored with Git LFS)
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user