【LOJ6202】—叶氏筛法(min_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
#define db double
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;
cs db eps=1e-10;
inline db C(ll x){return (double)(x+1)*(double)x/2;}
ll l,r;
double f1[N],f2[N];
inline db query(ll k){
if(!k)return 0;
int lim=sqrt(k);
for(int i=1;i<=lim;i++)f1[i]=C(i),f2[i]=C(k/i);
for(int p=2;p<=lim;p++){
if(fabs(f1[p]-f1[p-1])<=eps)continue;
cs double xx=p;
for(int i=1;i<=lim/p;i++)f2[i]-=(f2[i*p]-f1[p-1])*xx;
for(int i=lim/p+1;1.0*p*p*i<=k&&i<=lim;i++)f2[i]-=(f1[k/i/p]-f1[p-1])*xx;
for(int i=lim;i>=1.0*p*p;i--)f1[i]-=(f1[i/p]-f1[p-1])*xx;
}
return f2[1];
}
int main(){
scanf("%lld%lld",&l,&r);
printf("%.0lf",query(r)-query(l-1));
}