【LOJ6235】—区间素数个数(min_25筛)
_25模板题
不会的看这个
#include<bits/stdc++.h>
using namespace std;
const int RLEN=1<<20|1;
inline char gc(){
static char ibuf[RLEN],*ib,*ob;
(ib==ob)&&(ob=(ib=ibuf)+fread(ibuf,1,RLEN,stdin));
return (ib==ob)?EOF:*ib++;
}
#define gc getchar
inline int read(){
char ch=gc();
int res=0,f=1;
while(!isdigit(ch))f^=ch=='-',ch=gc();
while(isdigit(ch))res=(res+(res<<2)<<1)+(ch^48),ch=gc();
return f?res:-res;
}
#define pb push_back
#define ll long long
#define cs const
#define re register
#define pii pair<int,int>
#define fi first
#define se second
int mod;
inline int add(int a,int b){return (a+=b)>=mod?a-mod:a;}
inline void Add(int &a,int b){(a+=b)>=mod?a-=mod:0;}
inline int dec(int a,int b){return a>=b?a-=b:a-b+mod;}
inline void Dec(int &a,int b){(a-=b)<0?a+=mod:0;}
inline int mul(int a,int b){return 1ll*a*b>=mod?1ll*a*b%mod:a*b;}
inline void Mul(int &a,int b){a=mul(a,b);}
inline int ksm(int a,int b,int res=1){
for(;b;b>>=1,Mul(a,a))(b&1)&&(res=mul(res,a));return res;
}
cs int N=1000006;
ll f1[N],f2[N],n;
signed main(){
scanf("%lld",&n);
int lim=sqrt(n);
for(re int i=1;i<=lim;i++)f1[i]=i-1,f2[i]=n/i-1;
for(re int p=2;p<=lim;p++){
if(f1[p]==f1[p-1])continue;
for(re int i=1;i<=lim/p;i++)f2[i]-=f2[i*p]-f1[p-1];
for(re int i=lim/p+1;1ll*i*p*p<=n&&i<=lim;i++)f2[i]-=f1[n/i/p]-f1[p-1];
for(re int i=lim;i>=1ll*p*p;i--)f1[i]-=f1[i/p]-f1[p-1];
}
cout<<f2[1];
}