Tuesday, December 19, 2017

problem 6

 /*
        The sum of the squares of the first ten natural numbers is,

        385
        The square of the sum of the first ten natural numbers is,

        3025
        Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is 3025 − 385 = 2640.

        Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.
     */
    class Program
    {
        static void Main(string[] args)
        {
            System.Numerics.BigInteger sumOfSquares = 0;
            for (System.Numerics.BigInteger i = 1; i <= 100; i++)
            {
                sumOfSquares += (i * i);
            }

            System.Numerics.BigInteger sums = 0;
            for (int i = 1; i <= 100; i++)
            {
                sums = sums + i;
            }
            System.Numerics.BigInteger squareOfSums = sums * sums;

            Console.WriteLine(squareOfSums - sumOfSquares );
        }

    }

Problem 5

    /*
    2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.
    What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?
     */
    class Program
    {
        static void Main(string[] args)
        {
            bool divisible = false;
            int number = 1;
            while(divisible == false)
            {
                divisible = true;
                for(int i = 1; i<=20; i++)
                {
                    if((number%i) !=0  )
                    {
                        divisible = false;
                        break;
                    }
                }
                if(divisible==true)
                {
                    Console.WriteLine(number);
                    break;
                }
                else
                {
                    number++;
                }
            }
        }
    }