Exemplo n.º 1
0
        public void Run()
        {
            BigInteger sum = 0;

            //Ignore 1 and 2 as they are not sums
            for (int i = 3; i <= 1000000; i++)
            {
                if (i % 10000000 == 0)
                {
                    Console.WriteLine(i);
                }

                char[] characters = i.ToString()
                                    .ToCharArray();
                BigInteger interimResult = 0;
                foreach (char num in characters)
                {
                    interimResult += Factorials.GetFactorial(Int32.Parse(num.ToString()));
                }

                if (interimResult == i)
                {
                    Console.WriteLine(interimResult);
                    sum += interimResult;
                }
            }

            this.result = "The sum of factorions is:" + sum;
        }
    static void Main()
    {
        double e       = 1;
        int    counter = 1;
        // We would use it to know how many times to multiply "x" by itselft to get a proper power.
        int power = 1;

        // Ask a user to enter a number to use it as a power for e till the end of the app's runtime.
        Console.Write("Please enter a number to rise constant e to it's power: ");
        int x = int.Parse(Console.ReadLine());
        // A local variable to store "x's" powee
        int xPowered = x;

        // As soon as we are limited with maximum number integers and doubles can store, let's use 10 loops's precision.
        while (counter <= 10)
        {
            /* This loop would be executed once for every "counter's" value except the first one, where both "power" and "counter" equal to 1. When counter would be equal to 2, the loop would be executing once providing xPowered * x result stored in "xPowered", which is the second power of "x" - just what we need to the further calculations on the step. */
            while (power < counter)
            {
                xPowered *= x;
                ++power;
            }

            /* GetFactorial method returns an integer, so we need to cast in to double before use as divider for 1. */
            e += xPowered / (double)Factorials.GetFactorial(counter);
            ++counter;
        }

        Console.WriteLine($"The e constant provided by Math.E is:   {Math.Pow(Math.E, x)}");
        Console.WriteLine($"The e constant provided by thie app is: {e}");
    }
    static void Main()
    {
        double e       = 1;
        int    counter = 1;

        // As soon as we are limited with maximum number integers and doubles can store, let's use 10 loops's precision.
        while (counter <= 10)
        {
            // GetFactorial method returns an integer, so we need to cast in to double before use as divider for 1.
            e += 1 / (double)Factorials.GetFactorial(counter);
            ++counter;
        }

        Console.WriteLine($"The e constant provided by Math.E is:   {Math.E}");
        Console.WriteLine($"The e constant provided by thie app is: {e}");
    }
Exemplo n.º 4
0
        public void Solution()
        {
            long number;  //Variable containing estimated required number

            minNumber = Factorials.GetFactorial(lastNumber);


            for (int i = lastNumber - 2; i > 1; i--)
            {
                number = minNumber % Factorials.GetFactorial(i) == 0 ? minNumber / Factorials.GetFactorial(i) : minNumber;
                for (int j = lastNumber; j >= 1; j--)
                {
                    if (number % j != 0)
                    {
                        break;
                    }
                    if (j == 1)
                    {
                        minNumber = number;
                        i++;
                    }
                }
            }
        }