文章目錄

原题链接 http://projecteuler.net/problem=6

Sum square difference

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.

和平方差

前10个自然数的平方和是,

12 + 22 + … + 102 = 385

前10个自然数的和的平方是,

(1 + 2 + … + 10)2 = 552 = 3025

因此前10个自然数的和的平方与平方的和之间的差是 3025 - 385 = 2640.

求前100个自然数的和的平方与平方的和之间的差。

解答:

其实就是用公式

(1^2 + 2 ^2 + \ldots + n^2 = \frac{1}{6}n(n + 1)(2n + 1))

((1 + 2 + \ldots + n)^2 = (\frac{1}{2}n(n+1))^2)

打赏作者

文章目錄