2 条题解
-
0
#include<bits/stdc++.h> using namespace std; typedef long long LL; const int N=1e6; const LL P=1e9+7,inf=1e12; int pr, p[N+10];LL mu[N+10],s[N+10]; bool v[N+10]; void init() { memset(v,0,sizeof(v)); pr=0;mu[0]=0;mu[1]=1; for(int i=2;i<=N;i++) { if(!v[i]) p[++pr]=i,mu[i]=-1; for(int j=1;j<=pr&&p[j]*i<=N;j++) { v[i*p[j]]=true; if(i%p[j]==0){mu[i*p[j]]=0;break;} mu[i*p[j]]=-mu[i]; } } for(int i=1;i<=N;i++) s[i]=s[i-1]+mu[i]; } map<LL,LL> mps; LL S(LL x) { if(x<=N)return s[x]; if(mps[x]) return mps[x]; LL res=1; for(LL l=2,r;l<=x;l=r+1)//注意:l=2开始! { r=x/(x/l); res=(res-(r-l+1)*S(x/l)%P +P )%P; } return mps[x]=res; } LL qpow(LL a,LL b){LL res=1;for(;b;b>>=1,a=a*a%P)if(b&1)res=res*a%P; return res;} int main() { init(); LL n,k,L,R,ans=0;scanf("%lld%lld%lld%lld",&n,&k,&L,&R); L=(L-1)/k,R=R/k; for(LL l=1,r;l<=R;l=r+1) { r=min((L/l)?L/(L/l):inf,R/(R/l)); ans=(ans+(S(r)-S(l-1))*qpow(R/l-L/l,n)%P+P)%P; } printf("%lld\n",ans); return 0; } -
0
#include<bits/stdc++.h> using namespace std; typedef long long LL; const int N=1e6; const LL P=1e9+7,inf=1e12; int pr, p[N+10];LL mu[N+10],s[N+10]; bool v[N+10]; void init() { memset(v,0,sizeof(v)); pr=0;mu[0]=0;mu[1]=1; for(int i=2;i<=N;i++) { if(!v[i]) p[++pr]=i,mu[i]=-1; for(int j=1;j<=pr&&p[j]*i<=N;j++) { v[i*p[j]]=True; if(i%p[j]==0){mu[i*p[j]]=0;break;} mu[i*p[j]]=-mu[i]; } } for(int i=1;i<=N;i++) s[i]=s[i-1]+mu[i]; } map<LL,LL> mps; LL S(LL x) { if(x<=N)return s[x]; if(mps[x]) return mps[x]; LL res=1; for(LL l=2,r;l<=x;l=r+1)//注意:l=2开始! { r=x/(x/l); res=(res-(r-l+1)*S(x/l)%P +P )%P; } return mps[x]=res; } LL qpow(LL a,LL b){LL res=1;for(;b;b>>=1,a=a*a%P)if(b&1)res=res*a%P; return res;} int main() { init(); LL n,k,L,R,ans=0;scanf("%lld%lld%lld%lld",&n,&k,&L,&R); L=(L-1)/k,R=R/k; for(LL l=1,r;l<=R;l=r+1) { r=min(L/l?L/(L/l):inf,R/(R/l)); ans=(ans+(S(r)-S(l-1))*qpow(R/l-L/l,n)%P+P)%P; } printf("%lld\n",ans); return 0; }
- 1
信息
- ID
- 5595
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 9
- 标签
- 递交数
- 14
- 已通过
- 3
- 上传者