题解:
莫比乌斯函数
然而向我这种弱菜肯定选择暴力dp
代码:
#include<bits/stdc++.h> const int N=100010,M=1000000007; typedef long long ll; using namespace std; int n; ll m,L,R,k,f[N]; ll power(ll x,int y) { ll ans=1; while (y) { if (y&1)ans=ans*x%M; x=x*x%M; y>>=1; } return ans; } int main() { scanf("%d%lld%lld%lld",&n,&k,&L,&R); for (ll i=R-L;i>=1;i--) { ll l=(L-1)/(k*i),r=R/(k*i); f[i]=(power(r-l,n)-(r-l)+M)%M; for (int j=2;i*j<=R-L;j++)f[i]=(f[i]-f[i*j]+M)%M; } if (L<=k&&k<=R)f[1]++; printf("%d\n",f[1]); return 0; }