3 ms·
Slightly modified version, which uses some of the bounds adjustments suggested by other comments: int n = 100 vector<int> p(n); void sieve() {
by SomeStupidPoint 9y ago
Slightly modified version, which uses some of the bounds adjustments suggested by other comments:
int n = 100
vector<int> p(n);
void sieve()
{
for(int i = 2; i * i < n; i++) {
if (p[i] == 0) { // Could probably just !p[i]
for(int j = i * i; j < n; j += i) {
p[j]++;
}
}
}
}
bool is_prime(int k)
{
return p[k] == 0;
}