# [bzoj3930] [CQOI2015]选数

## Sample Input

2 2 2 4


## Sample Output

3


## solution

\begin{align} ans&=\sum_{a_1=L}^R\sum_{a_2=L}^R\dots\sum_{a_n=L}^R[gcd(a_1,a_2,\dots,a_n)=k]\\ &=\sum_{d=1}^{\lfloor\frac{R}{d}\rfloor}\mu(d)(\lfloor\frac{R}{kd}\rfloor-\lfloor\frac{L-1}{kd}\rfloor)^n \end{align}

#include<bits/stdc++.h>
using namespace std;

#define int long long

x=0;int f=1;char ch=getchar();
for(;!isdigit(ch);ch=getchar()) if(ch=='-') f=-f;
for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';x*=f;
}

void print(int x) {
if(x<0) x=-x,putchar('-');
if(!x) return ;print(x/10),putchar(x%10+48);
}
void write(int x) {if(!x) putchar('0');else print(x);putchar('\n');}

const int maxn = 1e7+1;
const int mod = 1000000007;

int pri[maxn],mu[maxn],vis[maxn],tot;

void sieve() {
mu[1]=1;
for(int i=2;i<maxn;i++) {
if(!vis[i]) pri[++tot]=i,mu[i]=-1;
for(int t,j=1;j<=tot&&i*pri[j]<maxn;j++) {
vis[t=i*pri[j]]=1;
if(!(i%pri[j])) {mu[t]=0;break;}
mu[t]=-mu[i];
}
}
for(int i=1;i<maxn;i++) mu[i]=mu[i-1]+mu[i];
}

map<int,int > Mu;

int sum_mu(int n) {
if(n<maxn) return mu[n];
if(Mu[n]) return Mu[n];//write(n);
int ans=1,T=2;
while(T<=n) {
int pre=T;T=n/(n/T);
ans=(ans-(T-pre+1)*sum_mu(n/T)%mod)%mod;T++;
}
return Mu[n]=(ans%mod+mod)%mod;
}

int qpow(int a,int x) {
int res=1;
for(;x;x>>=1,a=a*a%mod) if(x&1) res=res*a%mod;
return res;
}

signed main() {
sieve();