Exemplo n.º 1
0
        /// <summary>
        /// 2^15 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26.
        /// What is the sum of the digits of the number 2^1000?
        /// </summary>
        /// <returns></returns>
        public string Compute()
        {
            int          maxPower = 1000;
            ReallyBigInt result   = new ReallyBigInt("2");

            for (int power = 2; power <= maxPower; power++)
            {
                result = result.Addition(result);
            }
            long sum = MathLibrary.SumDigits(result);

            return(sum.ToString());
        }
        /// <summary>
        /// The Fibonacci sequence is defined by the recurrence relation:
        ///
        /// Fn = Fn−1 + Fn−2, where F1 = 1 and F2 = 1.
        ///
        /// Hence the first 12 terms will be:
        ///
        /// F1 = 1
        /// F2 = 1
        /// F3 = 2
        /// F4 = 3
        /// F5 = 5
        /// F6 = 8
        /// F7 = 13
        /// F8 = 21
        /// F9 = 34
        /// F10 = 55
        /// F11 = 89
        /// F12 = 144
        ///
        /// The 12th term, F12, is the first term to contain three digits.
        ///
        /// What is the first term in the Fibonacci sequence to contain 1000 digits?
        /// </summary>
        /// <returns></returns>
        public string Compute()
        {
            long         result        = 1;
            ReallyBigInt fibonacciPrev = new ReallyBigInt("0");
            ReallyBigInt fibonacci     = new ReallyBigInt("1");
            ReallyBigInt fibonacciSum;

            while (fibonacci.value.Length < 1000)
            {
                result++;
                fibonacciSum  = fibonacci.Addition(fibonacciPrev);
                fibonacciPrev = fibonacci;
                fibonacci     = fibonacciSum;
            }
            return(result.ToString());
        }
Exemplo n.º 3
0
        public string Compute()
        {
            ReallyBigInt result = new ReallyBigInt("0");
            ReallyBigInt number = new ReallyBigInt("0");

            for (long index = 1; index <= max; index++)
            {
                System.Console.Write((index - 1).ToString() + " ");
                if (MathLibrary.IsMultiple(index, 10))
                {
                    continue;
                }

                number = new ReallyBigInt(index.ToString());
                number = number.Power(index);

                result = result.Addition(number);
            }
            return(result.value);
        }