# bzoj2655:calc

### 传送门

$f(n)=\frac{1}{n}\sum_{i=1}^{A}f(n,i)$

$f(n,x)=x(f(n-1)-f(n-1,x))\\ x^if(n-i-1)=x^{i}f(n-i-1,x)+x^{i-1}f(n-i,x)\\ x^if(n-i)=x^{i}f(n-i,x)+x^{i-1}f(n-i+1,x)\\$

$f(n,x)=\sum_{i=1}^{n}(-1)^{i+1}x^if(n-i)$

$f(n)=\frac{1}{n}\sum_{j=1}^{A}\sum_{i=1}^{n}(-1)^{i+1}j^if(n-i)\\ f(n)=\frac{1}{n}\sum_{i=1}^{n}(-1)^{i+1}\sum_{j=1}^{A}j^if(n-i)\\$

#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
void read(int &x) {
char ch; bool ok;
for(ok=0,ch=getchar(); !isdigit(ch); ch=getchar()) if(ch=='-') ok=1;
for(x=0; isdigit(ch); x=x*10+ch-'0',ch=getchar()); if(ok) x=-x;
}
#define rg register
const int maxn=510;
int n,m,mod,fac[maxn],facinv[maxn],B[maxn],inv[maxn],g[maxn],f[maxn];
int mul(int x,int y){return 1ll*x*y-1ll*x*y/mod*mod;}
int del(int x,int y){return x-y<0?x-y+mod:x-y;}
int add(int x,int y){return x+y>=mod?x+y-mod:x+y;}
int mi(int a,int b){
int ans=1;while(b){if(b&1)ans=mul(ans,a);b>>=1,a=mul(a,a);}
return ans;
}
int C(int n,int m){return mul(fac[n],mul(facinv[m],facinv[n-m]));}
int main()
{
fac[0]=inv[0]=facinv[0]=B[0]=1;
for(rg int i=1;i<=n+1;i++)fac[i]=mul(fac[i-1],i),inv[i]=mi(i,mod-2);
facinv[n+1]=mi(fac[n+1],mod-2);
for(rg int i=n;i;i--)facinv[i]=mul(facinv[i+1],i+1);
for(rg int i=1;i<=n;i++){
B[i]=del(mod,mul(B[i],inv[i+1]));
}
for(rg int i=1;i<=n;i++){
}