1:  /// -------- ToujoursEnBeta
   2:  /// Author & Copyright : Peter Luschny
   3:  /// License: LGPL version 3.0 or (at your option)
   4:  /// Creative Commons Attribution-ShareAlike 3.0
   5:  /// Comments mail to: peter(at)luschny.de
   6:  /// Created: 2010-03-01
   7:   
   8:  namespace Sharith.Math.Factorial 
   9:  {
  10:      using XInt = Sharith.Arithmetic.XInt;
  11:   
  12:      public class ProductRecursive : IFactorialFunction 
  13:      {
  14:          public ProductRecursive() { }
  15:   
  16:          public string Name
  17:          {
  18:              get { return "ProductRecursive    "; }
  19:          }
  20:   
  21:          public XInt Factorial(int n)
  22:          {
  23:              if (n < 0)
  24:              {
  25:                  throw new System.ArgumentOutOfRangeException("n",
  26:                  Name + ": n >= 0 required, but was " + n);
  27:              }
  28:   
  29:              if (1 < n)
  30:              {
  31:                  return RecProduct(1, n);
  32:              }
  33:   
  34:              return XInt.One;
  35:          }
  36:   
  37:          private XInt RecProduct(int n, int len)
  38:          {
  39:              if (1 < len)
  40:              {
  41:                  int l = len >> 1;
  42:                  return RecProduct(n, l) * RecProduct(n + l, len - l);
  43:              }
  44:   
  45:              return new XInt(n);
  46:          }
  47:      }
  48:  }   // endOfFactorialProductRecursive