eBash

It is not the mountain we conquer but ourselves

Project Euler Problem 6

| Comments

Table of Contents

1 Problem

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.

2 Solution

可以直接依定义计算12 + 22 + … + n2,(1 + 2 + … + n)2 再相减,或者利用简单的初等数学:

\begin{eqnarray} \sum_{i=1}^na_{i} = \frac{(1+n) n}{2} \end{eqnarray} \begin{eqnarray} \sum_{i=1}^n a^2_i = \frac{(2n+1)(n+1)n}{6} \end{eqnarray}

3 Answer

25164150

Source:C++

Comments