aboutsummaryrefslogtreecommitdiff
path: root/Math
diff options
context:
space:
mode:
authorTa180m2020-05-02 21:30:50 -0500
committerTa180m2020-05-02 21:30:50 -0500
commit57b712b96153536c50ccb028d2370a3d6c813a9f (patch)
tree87e19a9621d38d944167fdbbf2ff261d37d75d2f /Math
parent642183438c3de2ea1fc630c845492a1dfd77323e (diff)
Update primes.cpp
Diffstat (limited to 'Math')
-rw-r--r--Math/primes.cpp8
1 files changed, 4 insertions, 4 deletions
diff --git a/Math/primes.cpp b/Math/primes.cpp
index 3420fe1..6df51ba 100644
--- a/Math/primes.cpp
+++ b/Math/primes.cpp
@@ -3,16 +3,16 @@ bitset<10000001> bs;
vector<int> pr;
void sieve(int size) {
- sieve_size = size + 1;
+ sieve_size = size;
bs.set(); bs[0] = bs[1] = 0;
- for (ll i = 2; i < sieve_size; ++i) if (bs[i]) {
- for (ll j = i * i; j < sieve_size; j += i) bs[j] = 0;
+ for (ll i = 2; i <= sieve_size; ++i) if (bs[i]) {
+ for (ll j = i * i; j <= sieve_size; j += i) bs[j] = 0;
pr.push_back(i);
}
}
bool is_prime(ll N) {
- if (N < sieve_size) return bs[N];
+ if (N <= sieve_size) return bs[N];
for (int i = 0; i < pr.size() && pr[i] * pr[i] <= N; ++i) if (N % pr[i] == 0) return false;
return true;
}