Project Euler : Sum Of Both Diagonals In A 1001 By 1001 Spiral

This one I solved using just paper and pencil, and am happy about it. All that was required was a keen observation on how the numbers along the diagonal form out of the previous number. Lets take a look at one of the diagonals of the 5 x 5 spiral

21     22     23     24     25
20     07     08     09     10
19     06     01     02     11
18     05     04     03     12
17     16     15     14     13

Consider the numbers along the diagonal originating in the center at 01 moving towards the upper right corner. The numbers are 01, 09, 25. Let me tell you that the next number along this diagonal will be 49. Do you see any pattern emerging yet?

Well, all these number are squares -

1^2 = 1

3^2 = 9

5^2 = 25

7^2 = 49

Considering the distance of the number from the center of the spiral as a parameter, this series can be written as:

d_1 = (2n + 1) ^2

\implies d_1 = 4n^2 + 4n + 1

The numbers along the other diagonals are simply derived from d_1 by subtracting certain values.

d_2 = d_1 - 2n

\implies d_2 = 4n^2 + 2n + 1

d_3 = d_2 - 2n

\implies d_3 = 4n^2 + 1

d_4 = d_3 - 2n

\implies d_4 = 4n^2 - 2n + 1

Now, all that the problem asks us to do is to sum up the numbers d_1, d_2, d_3, d_4 for n = 1, 2, \ldots 500.

sum = \Sigma(16n^2 + 4n + 4) for n = 1, 2 \ldots 500

This is a simple summing up exercise. Solved !!

Popularity: 7% [?]

Related posts:

  1. Project Euler 43: Pandigital Numbers With Unusual Substring Divisibility Property
  2. Project Euler : n Digit Integers That Are Also nth Power
  3. Project Euler : Find Hexagonal Pentagonal Number
  4. Project Euler : Finding The nth Digit Of The Fractional Part Of Irrational Number
  5. Project Euler : Finding The Largest Prime Factor Of A Given Number