BZOJ 3930 容斥原理
思路:
移至iwtwiioi http://www.cnblogs.com/iwtwiioi/p/4986316.html
//By SiriusRen #include <cstdio> #include <cstring> #include <algorithm> using namespace std; #define int long long const int mod=1000000007; int n,k,l,h,f[100050]; int pow(int x,int y){ int res=1; while(y){ if(y&1)res=res*x%mod; x=x*x%mod,y>>=1; }return res; } signed main(){ scanf("%lld%lld%lld%lld",&n,&k,&l,&h); for(int i=h-l;i;i--){ int L=(l-1)/(k*i),R=h/(k*i); f[i]+=(pow(R-L,n)-R+L+mod)%mod; for(int j=2;i*j<=h-l;j++)(f[i]-=f[i*j])%=mod; f[i]=(f[i]+mod)%mod; }printf("%lld\n",(f[1]+(k>=l&&k<=h))%mod); }