[BZOJ 3601] 一个人的数论

题意

$\sum_{k=1,k\perp N}^{N-1} k^K$

题解

\begin{aligned} \text{Ans}&=\sum_{i=1}^N[i\perp N]i^K \\ &=\sum_{i=1}^N\sum_{d|i,d|N} \mu(d)i^K\\ &=\sum_{d|N}\sum_{k=1}^{\frac N d}\mu(d)(kd)^K \\ &=\sum_{d|N}\mu(d)d^K\sum_{k=1}^{\frac nd}k^K \end{aligned}

PS: 后来问Cage发现其实斯特林数也是能以比较简单的形式代入自然数幂和的, 它的形式是这样的:

n^m=\sum_{k=0}^m \begin{Bmatrix}m \\ k\end{Bmatrix} n^{\underline k} \\ \begin{aligned} \sum_{x=0}^nx^m&=\sum_{x=0}^{n}\sum_{k=0}^m \begin{Bmatrix}m \\ k\end{Bmatrix} x^{\underline k} \\ &=\sum_{k=0}^m\begin{Bmatrix}m \\ k\end{Bmatrix} \sum_{x=0}^n x^{\underline k} \end{aligned}

$\Delta(x^\underline n)=nx^\underline{n-1} \\ \sum x^\underline n\delta x=\frac {x^\underline{n+1}}{n+1}$

$\sum_{x=0}^nx^m=\sum_{k=0}^m\begin{Bmatrix}m \\ k\end{Bmatrix} \frac{x^\underline{m+1}}{m+1}$

\begin{aligned} \text{Ans}&=\sum_{d|N}\mu(d)d^K \sum_{i=0}^K\frac 1{K+1}B_i{K+1\choose i}\left (\frac N d\right)^{K+1-i}\\ &=\sum_{d|N}\sum_{i=0}^K\mu(d)d^K\frac 1{K+1}B_i{K+1\choose i}\left (\frac N d\right)^{K+1-i}\\ &=\sum_{i=0}^K\sum_{d|N}\mu(d)d^K\frac 1{K+1}B_i{K+1\choose i}\left (\frac N d\right)^{K+1-i}\\ &=\frac 1{K+1}\sum_{i=0}^KB_i{K+1\choose i}\sum_{d|N}\mu(d)d^K\left (\frac N d\right)^{K+1-i}\\ \end{aligned}

\begin{aligned} \text{Ans}&=\frac 1{K+1}\sum_{i=0}^KB_i{K+1\choose i}\sum_{d|N}\mu(d)N^K\left (\frac N d\right)^{1-i}\\ &=\frac {N^K}{K+1}\sum_{i=0}^KB_i{K+1\choose i}\sum_{d|N}\mu(d)\left (\frac N d\right)^{1-i} \end{aligned}

$\sum_{d|N}\mu(d)\left (\frac N d\right)^{1-i}=\prod_{k=1}^n \left (\left(p_k^{r_k}\right)^{1-i}-\left (p_k^{r_k-1}\right)^{1-i}\right)$

$\frac {N^K}{K+1}\sum_{i=0}^KB_i{K+1\choose i}\prod_{k=1}^n \left (\left(p_k^{r_k}\right)^{1-i}-\left (p_k^{r_k-1}\right)^{1-i}\right)$

参考代码

#include <bits/stdc++.h>

const int MAXN=1010;
const int MOD=1e9+7;
const int PHI=MOD-1;

int n;
int K;
int p[MAXN];
int r[MAXN];
int B[MAXN]; // Bernoulli
int inv[MAXN];
int fact[MAXN];

int C(int,int);
int Pow(int,int,int);

int main(){
scanf("%d%d",&K,&n);
int N=1;
for(int i=1;i<=n;i++){
scanf("%d%d",p+i,r+i);
N=1ll*N*Pow(p[i],r[i],MOD)%MOD;
}
fact[0]=1;
for(int i=1;i<=K+1;i++)
fact[i]=1ll*fact[i-1]*i%MOD;
inv[K+1]=Pow(fact[K+1],MOD-2,MOD);
for(int i=K+1;i>=1;i--)
inv[i-1]=1ll*inv[i]*i%MOD;
B[0]=1;
for(int i=1;i<=K;i++){
int sum=0;
for(int j=0;j<i;j++)
(sum+=1ll*C(i+1,j)*B[j]%MOD)%=MOD;
B[i]=1ll*(MOD-sum)*Pow(C(i+1,i),MOD-2,MOD)%MOD;
}
int ans=0;
for(int i=0;i<=K;i++){
int prod=1;
for(int j=1;j<=n;j++)
prod=1ll*prod*(Pow(p[j],1ll*r[j]*(MOD-i)%PHI,MOD)+MOD-Pow(p[j],1ll*(r[j]-1)*(MOD-i)%PHI,MOD))%MOD;
(ans+=1ll*B[i]*C(K+1,i)%MOD*prod%MOD)%=MOD;
}
ans=1ll*ans*Pow(K+1,MOD-2,MOD)%MOD*Pow(N,K,MOD)%MOD;
printf("%d\n",ans);
return 0;
}

int C(int n,int m){
return n<0||m<0||n<m?0:1ll*fact[n]*inv[m]%MOD*inv[n-m]%MOD;
}

inline int Pow(int a,int n,int p){
int ans=1;
while(n>0){
if(n&1)
ans=1ll*a*ans%p;
a=1ll*a*a%p;
n>>=1;
}
return ans;
}



posted @ 2019-06-16 19:38  rvalue  阅读(536)  评论(0编辑  收藏  举报