#include <iostream>
#include <vector>
using namespace std;
class Solution {
public:
int countPrimes(
int n) {
if(n<=
2)
return 0;
vector<bool> tmp(n,
false);
int i=
3,res=
1;
int upbound=
sqrt(n);
for(;i<n;i+=
2)
{
if(!tmp[i])
{
res++;
if(i>upbound)
continue;
for(
int j=i*i;j<n;j+=i)
tmp[j]=
true;
}
}
return res;
}
};
int main()
{
Solution mys;
int n=
2;
cout<<mys.countPrimes(n)<<endl;
return 0;
}
转载请注明原文地址: https://www.6miu.com/read-15369.html