bernoulli数-LMLPHP

LL B[N][],C[N][N],f[N][];
int n,m; LL gcd(LL a,LL b){return b?gcd(b,a%b):a;}
LL lcm(LL a,LL b){return a/gcd(a,b)*b;} void getC(int n)
{
int i,j;
n++;
for(i=;i<=n;i++)C[i][]=C[i][i]=;
for(i=;i<=n;i++){
for(j=;j<n;j++){
C[i][j]=C[i-][j-]+C[i-][j];
}
}
} void bernoulli(int n)
{
int i,m;
LL s[],b[],l,g;
B[][]=;B[][]=;
for(m=;m<=n;m++){
s[]=,s[]=;
for(i=;i<m;i++){
b[]=C[m+][i]*B[i][];
b[]=B[i][];
l=lcm(s[],b[]);
s[]=l/s[]*s[]+l/b[]*b[];
s[]=l;
}
s[]=-s[];
if(s[]){
g=gcd(s[],s[]*C[m+][m]);
B[m][]=s[]/g;
B[m][]=s[]*C[m+][m]/g;
}
else B[m][]=,B[m][]=;
}
} main()
int i,j;
LL g,maxlcm;
getC();
bernoulli();
while(~scanf("%d",&m))
{
for(i=;i<=m;i++){
g=gcd(C[m+][i],B[i][]);
f[i][]=C[m+][i]/g*B[i][];
f[i][]=B[i][]/g;
}
maxlcm=f[][];
for(i=;i<=m;i++){
maxlcm=lcm(maxlcm,f[i][]);
}
if(maxlcm<)maxlcm=-maxlcm;
for(i=;i<=m;i++){
f[i][]*=maxlcm/f[i][];
}
f[][]+=maxlcm*(m+); printf("%I64d",(m+)*maxlcm);
for(i=;i<=m;i++)
printf(" %I64d",f[i][]);
printf(" 0\n");
}
05-04 10:52