示例#1
0
文件: LargeInt.cs 项目: jonnu/euler
 public LargeInt(LargeInt initialValue)
 {
     for (int i = 0; i < initialValue.Length; i++)
     {
         SetDigitAt(i, initialValue.GetDigitAt(i));
     }
 }
示例#2
0
文件: Problem55.cs 项目: jonnu/euler
        private bool IsLychrelNumber(LargeInt value, int loopLimit)
        {
            while (loopLimit > 0)
            {
                value += new LargeInt(value).Reverse();
                if (value.Palindrome())
                    return false;

                loopLimit--;
            }

            return true;
        }
示例#3
0
文件: Problem57.cs 项目: jonnu/euler
        public void Next()
        {
            Iteration++;

            if (Iteration > 1)
            {
                // Add 1
                Numerator += Denominator;

                // Flip
                LargeInt temporary = Numerator;
                Numerator = Denominator;
                Denominator = temporary;
            }

            // Add 1
            Numerator += Denominator;
        }
示例#4
0
文件: LargeInt.cs 项目: jonnu/euler
        public static LargeInt Pow(LargeInt x, int y)
        {
            for (int i = 1; i < y; i++)
            {
                x *= x;
            }

            return x;
        }
示例#5
0
文件: LargeInt.cs 项目: jonnu/euler
        public static LargeInt Pow(int x, int y)
        {
            LargeInt integer = new LargeInt(x);
            for (int i = 1; i < y; i++)
            {
                integer = LargeInt.Multiply(integer, x);
            }

            return integer;
        }
示例#6
0
文件: LargeInt.cs 项目: jonnu/euler
        public static LargeInt Multiply(LargeInt x, int y)
        {
            LargeInt integer = new LargeInt(x);
            for (int i = 1; i < y; i++)
            {
                integer += x;
            }

            return integer;
        }
示例#7
0
文件: LargeInt.cs 项目: jonnu/euler
        public static LargeInt Multiply(LargeInt x, LargeInt y)
        {
            LargeInt newInt = new LargeInt();

            for (int i = 0; i < y.Length; i++)
            {
                int carry = 0;
                for (int j = 0; j < x.Length; j++)
                {
                    int zDigit = (y.GetDigitAt(i) * x.GetDigitAt(j)) + newInt.GetDigitAt(i + j) + carry;

                    newInt.SetDigitAt(i + j, zDigit % 10);
                    carry = zDigit / 10;
                }

                newInt.SetDigitAt(i + x.Length, carry);
            }

            return newInt;
        }
示例#8
0
文件: LargeInt.cs 项目: jonnu/euler
        public static LargeInt Add(LargeInt x, LargeInt y)
        {
            int carry = 0;
            int loopLength = Math.Max(x.Length, y.Length) + 1;
            LargeInt newInt = new LargeInt();

            for (int i = 0; i < loopLength; i++)
            {
                int xDigit = 0, yDigit = 0, zDigit = 0;

                xDigit = x.GetDigitAt(i);
                yDigit = y.GetDigitAt(i);
                zDigit = xDigit + yDigit + carry;

                if (zDigit >= radix)
                {
                    zDigit %= radix;
                    carry = 1;
                }
                else
                {
                    carry = 0;
                }

                newInt.SetDigitAt(i, zDigit);
            }

            return newInt;
        }