#include<iostream>
#define LL long long
#define maxn 1000010
using namespace std;
LL read()
{
LL x=0,f=1;
char c=getchar();
while(!isdigit(c)){if(c==‘-‘)f=-1;c=getchar();}
while(isdigit(c)){x=x*10+c-‘0‘;c=getchar();}
return x*f;
}
bool prime[maxn];
LL a;
void prime_table()
{
for(int i=2;(LL)i<=a;i++) prime[i]=1;
for(int i=2;(LL)i*i<=a;i++)
if(prime[i]) for(LL j=i*i;j<=a;j+=i) prime[j]=0;
return;
}
int main()
{
a=read();
prime_table();
int cnt=0;
for(int i=2;i<=a;i++)if(prime[i]) cnt++;
printf("%d\n", cnt);
//system("pause");
return 0;
}
时间: 2024-11-08 21:22:06