diff --git a/Luogu/P1835/P1835.cpp b/Luogu/P1835/P1835.cpp new file mode 100644 index 00000000..e3de06a3 --- /dev/null +++ b/Luogu/P1835/P1835.cpp @@ -0,0 +1,36 @@ +#include +#include + +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; +} diff --git a/Luogu/P1835/data/P1835_6.in b/Luogu/P1835/data/P1835_6.in new file mode 100644 index 00000000..ae7ef73a --- /dev/null +++ b/Luogu/P1835/data/P1835_6.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d4d32de059d98f955a839c6479cd42366ada9e2f4fa13383a97fe1600cb31c77 +size 23 diff --git a/Luogu/P1835/data/P1835_6.out b/Luogu/P1835/data/P1835_6.out new file mode 100644 index 00000000..95e61d4d --- /dev/null +++ b/Luogu/P1835/data/P1835_6.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:04f7a536c998611c87020ccd600123cd0c42931a1a211919524ab3bd8a971c43 +size 7