<< 接上篇

已知 a0 = 1 - 1/e, an = 1 - nan-1 (n > 0),我们有:

a0 = -(1/e - 1)
a1 = +(1/e - 0)
a2 = -(2/e - 1)
a3 = +(6/e - 2)
a4 = -(24/e - 9)
a5 = +(120/e - 44)
a6 = -(720/e - 265)

显然

an = (-1)n+1(n!/e - bn)

利用 1,0,1,2,9,44,265 在 OEIS 上搜索,得到 OEIS A000166,因此:

an = (-1)n+1(n!/e - !n)

其中:

因此:

而最后一行的表达式收敛极快,于是我们可以用以下 C 语言程序来计算 a999

#include <stdio.h>
#include <math.h>

double a(int n)
{
  double v = 0, t = 1;
  for (n++; t != 0; n++) t /= n, v += t, t = -t;
  return v;
}

int main(void)
{
  double v = 1 - 1 / M_E;
  for (int i = 1; i <= 1000; v = 1 - i++ * v)
    if (i < 5 || (i > 15 && i < 23) || i > 998)
      printf("a(%3d): %.12lf %16.12lf\n", i-1, a(i-1), v);
}

运行结果:

a(  0): 0.632120558829   0.632120558829
a(  1): 0.367879441171   0.367879441171
a(  2): 0.264241117657   0.264241117657
a(  3): 0.207276647029   0.207276647029
a( 15): 0.059017540879   0.059033793642
a( 16): 0.055719345931   0.055459301730
a( 17): 0.052771119169   0.057191870597
a( 18): 0.050119854958  -0.029453670752
a( 19): 0.047722755796   1.559619744279
a( 20): 0.045544884076 -30.192394885584
a( 21): 0.043557434408 635.040292597259
a(998): 0.001000000999             -inf
a(999): 0.000999001995              inf

参考资料

  1. OEIS A000166: Subfactorial or rencontres numbers, or derangements: number of permutations of n elements with no fixed points.
  2. Wolfram MathWorld: Subfactorial

>> 接下篇