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 欧拉计划 第6题 What is the difference between the sum of the squares and the square of the sums?和的平方与平方的和的差。 385 = 2640.

Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.

(a+b+c)^2-(a^2+b^2+c^2)=a^2+b^2+c^2+2ab+2ac+2bc-a^2-b^2-c^2 =2(ab+ab+bc)

结论:任意2个不同数向乘的累加和的2倍。

static void Main(string[] args)
        {
            long startTime, endTime;
            Int64 f=0;
            int i,j;
            startTime = DateTime.Now.Ticks;
            for (i = 1; i <= 99; i++)
            {
                for (j = i + 1; j <= 100; j++)
                {
                    f += i * j;
                }
            }
            endTime = DateTime.Now.Ticks;
            Console.WriteLine("result:{0}  run time:{1} ms",2*f,(endTime-startTime)/10000.0);
            Console.ReadLine();
        }

 结果:25164150

 

相关文章:

  • 2021-08-11
  • 2021-12-12
  • 2021-12-03
  • 2022-03-07
  • 2021-12-13
  • 2021-10-08
  • 2021-07-10
  • 2022-01-08
猜你喜欢
  • 2022-03-08
  • 2022-12-23
  • 2022-01-04
  • 2022-02-26
  • 2021-09-17
  • 2021-07-22
  • 2021-08-28
相关资源
相似解决方案