1: package de.luschny.math.factorial;
2:
3: import de.luschny.math.arithmetic.Xint;
4:
5: public class FactorialAdditiveMoessner implements IFactorialFunction
6: {
7:
8: public FactorialAdditiveMoessner()
9: {
10: }
11:
12: public String getName()
13: {
14: return "AdditiveMoessner ";
15: }
16:
17: public Xint factorial(int n)
18: {
19: if (n < 0)
20: {
21: throw new ArithmeticException("Factorial: n has to be >= 0, but was " + n);
22: }
23:
24: Xint[] s = new Xint[n + 1];
25: s[0] = Xint.ONE;
26:
27: for (int m = 1; m <= n; m++)
28: {
29: s[m] = Xint.ZERO;
30: for (int k = m; k >= 1; k--)
31: {
32: for (int i = 1; i <= k; i++)
33: {
34: s[i] = s[i].add(s[i - 1]);
35: }
36: }
37: }
38: return s[n];
39: }
40: } // endOfFactorialMoessner