唐睿

A full stack engineer, an architecture, a project coordinator and an entrepreneur, who is always learning.

偶然间发现一个 π 的算法

16 May 2006 » 技术
编程 算法 π
long a = 10000, b = 0, c = 2800, d, e = 0, f[2801], g;

main() {
  for (; b - c;) f[b++] = a / 5;
  for (; d = 0, g = c * 2; c -= 14, printf("%.4d", e + d / a), e = d % a);
  for (b = c; d += f[b] * a, f[b] = d % --g, d /= g--, --b; d *= b);
}

结果是:

5926 5358 9793 2384 6264 3383 2795 0288 4197 1693 9937 5105 8209 7494 4592 3078 1640 6286 2089 9862 8034 8253 4211 7067 9821 4808 6513 2823 0664 7093 8446 0955 0582 2317 2535 9408 1284 8111 7450 2841 0270 1938 5211 0555 9644 6229 4895 4930 3819 6442 8810 9756 6593 3446 1284 7564 8233 7867 8316 5271 2019 0914 5648 5669 2346 0348 6104 5432 6648 2133 9360 7260 2491 4127 3724 5870 0660 6315 5881