1: using Xint = System.Numerics.BigInteger;
2:
3:
4: namespace Luschny.Math.Factorial
5: {
6: public class FactorialAdditiveMoessner : IFactorialFunction
7: {
8: public FactorialAdditiveMoessner() { }
9:
10: public string Name
11: {
12: get { return "AdditiveMoessner "; }
13: }
14:
15: public Xint Factorial(int n)
16: {
17: if (n < 0)
18: {
19: throw new System.ArgumentOutOfRangeException("n",
20: Name + ": n >= 0 required, but was " + n);
21: }
22:
23: Xint[] s = new Xint[n + 1];
24: s[0] = Xint.One;
25:
26: for (int m = 1; m <= n; m++)
27: {
28: s[m] = Xint.Zero;
29: for (int k = m; k >= 1; k--)
30: {
31: for (int i = 1; i <= k; i++)
32: {
33: s[i] += s[i - 1];
34: }
35: }
36: }
37: return s[n];
38: }
39: }
40: } // endOfFactorialAdditiveMoessner