标签:n+1 uri ast ret ++i 复试 new class prim
Eratasthene
学问之道无他,求其放心而巳矣
https://blog.csdn.net/qq_37653144/article/details/80470029
class Solution1 {
public:
size_t countPrimes(size_t n) {
bool *p = new bool[n+1];
size_t i, j;
for (i = 0; i <= n; ++i)
p[i] = true;
p[0] = p[1] = false;
for (i = 2; i < n; ++i)
if (p[i])
for (j = 2; i*j < n; ++j)
p[i*j] = false;
size_t cnt = 0;
for (i = 2; i < n; ++i)
if (p[i])
cnt++;
delete []p;
return cnt;
}
};
标签:n+1 uri ast ret ++i 复试 new class prim
原文地址:https://www.cnblogs.com/paulkg12/p/12240065.html