1: package de.luschny.math.factorial;
2:
3: import de.luschny.math.arithmetic.Xint;
4:
5: public class FactorialProductRecursive implements IFactorialFunction
6: {
7:
8: public FactorialProductRecursive()
9: {
10: }
11:
12: public String getName()
13: {
14: return "ProductRecursive ";
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: if (1 < n)
25: {
26: return recProduct(1, n);
27: }
28:
29: return Xint.ONE;
30: }
31:
32: private Xint recProduct(int n, int len)
33: {
34: if (1 < len)
35: {
36: int l = len / 2;
37: return recProduct(n, l).multiply(recProduct(n + l, len - l));
38: }
39:
40: return Xint.valueOf(n);
41: }
42: } // endOfFactorialProductRecursive