Topic See HTTP://PAN.BAIDU.COM/S/1O6ZAJC2
Also do not know h-l<=10^5 this condition is why ....
#include <map> #include <cstdio> #include <cstring> #include <iostream> #include <algorithm&
Gt
#define M 10001000 #define INF 0x3f3f3f3f #define MOD 1000000007 using namespace std;
int Mu[m],prime[1001001],tot;
BOOL Not_prime[m];
Map<int,long long> mu_sum;
Long Long n,d,l,r;
void Linear_shaker () {int i,j;
Mu[1]=1;
for (i=2;i<=10000000;i++) {if (!not_prime[i]) {mu[i]=-1;
Prime[++tot]=i;
} for (j=1;prime[j]*i<=10000000;j++) {not_prime[prime[j]*i]=true;
if (i%prime[j]==0) {mu[prime[j]*i]=0;
Break
} Mu[prime[j]*i]=-mu[i];
}} for (i=1;i<=10000000;i++) mu[i]+=mu[i-1];
A long long mu_sum (int x) {if (x<=10000000) return mu[x];
if (Mu_sum.find (x)!=mu_sum.end ()) return mu_sum[x];
Long Long i,last,re=1;
for (i=1;i<=x;i=last+1) {last=x/(x/i);
if (x/i-1) re-= (Mu_sum (last)-mu_sum (i-1)) * (x/i-1);
} return mu_sum[x]=re;
A long long quick_power (long long x,int y) {long long re=1; WhileY) {if (y&1) (re*=x)%=mod; (x*=x)%=mod;
y>>=1;
} return re;
} Long Long Solve () {long i,last,re=0; for (i=1;i<=r;i=last+1) {last=min (r/(r/i), l/i? (
l/(l/i)): INF);
re+= (Mu_sum (last)-mu_sum (i-1)) *quick_power (r/i-l/i,n);
Re%=mod;
} return (Re%mod+mod)%mod;
} int main () {cin>>n>>d>>l>>r;
L= (L-1)/d;r=r/d;
Linear_shaker ();
Cout<<solve () <<endl;
}