【ProjectEuler】ProjectEuler_006

// The sum of the squares of the first ten natural numbers is,
// 
// 12 + 22 + ... + 102 = 385
// The square of the sum of the first ten natural numbers is,
// 
// (1 + 2 + ... + 10)2 = 552 = 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.

using System;
using System.Collections.Generic;
using System.Text;

namespace projecteuler006
{
    class Program
    {
        static void Main(string[] args)
        {
            F1();
        }

        private static void F1()
        {
            Console.WriteLine(new System.Diagnostics.StackTrace().GetFrame(0).GetMethod());
            DateTime timeStart = DateTime.Now;

            int maxValue = 100;
            long sum = 0;
            long square = 0;

            for (int i = 1; i <= maxValue; i++)
            {
                sum += i * i;
                square += i;
            }
            square *= square;

            Console.WriteLine(square + " - " + sum + " = " + (square - sum));
            Console.WriteLine("Total Milliseconds is " + DateTime.Now.Subtract(timeStart).TotalMilliseconds + "\n\n");
        }
    }
}

/*
Void F1()
25502500 - 338350 = 25164150
Total Milliseconds is 1.5002

By GodMoon
*/

你可能感兴趣的:(【ProjectEuler】ProjectEuler_006)