Product() static public method

static public Product ( long seq, int start, int len ) : Arithmetic.XInt
seq long
start int
len int
return Arithmetic.XInt
Example #1
0
        public XInt GetPrimorial(uint min, uint max)
        {
            var mem   = (int)(0.63 * max / System.Math.Log(max));
            var plist = new long[mem];
            var size  = 0;

            if (min <= 2)
            {
                plist[size++] = 2;
            }
            if (min <= 3)
            {
                plist[size++] = 3;
            }

            var  absPos = (int)((min + (min + 1) % 2) / 3 - 1);
            var  index  = absPos / BitsPerInt;
            var  bitPos = absPos % BitsPerInt;
            bool toggle = (bitPos & 1) == 1;
            var  prime  = (uint)(5 + 3 * (BitsPerInt * index + bitPos) - (bitPos & 1));

            while (prime <= max)
            {
                var bitField = this.isComposite[index++] >> bitPos;
                for (; bitPos < BitsPerInt; bitPos++)
                {
                    if ((bitField & 1) == 0)
                    {
                        plist[size++] = prime;
                    }
                    prime += (toggle = !toggle) ? 2u : 4u;
                    if (prime > max)
                    {
                        return(MathFun.Product(plist, 0, size));
                    }
                    bitField >>= 1;
                }
                bitPos = 0;
            }
            return(XInt.Zero);
        }
Example #2
0
 public XInt Product()
 {
     this.factors[this.count++] = this.prod;
     return(MathFun.Product(this.factors, 0, this.count));
 }