Skip to content

Latest commit

 

History

History
34 lines (23 loc) · 995 Bytes

p0028.md

File metadata and controls

34 lines (23 loc) · 995 Bytes

[<] [^] | [>]

Problem 28: Number Spiral Diagonals

The link to the problem

My approach

Think in cases of the starting point and other squares.

The number of starting point is $1$, and the number of upper right corner of nth square is $(2n + 1)^{2} \ \ (n \ge 1)$. Let $f(n)$ is the sum of the four corners of nth square:

$$ \begin{align} f(n) & = (2n + 1)^{2} + ((2n + 1)^{2} - 2n) + ((2n + 1)^{2} - 4n) + ((2n + 1)^{2} - 6n) \\ & = 16n^{2} + 4n + 4 \end{align} $$

And then, a square $1001$ by $1001$ is the $(1001 - 1) / 2 =$ 500th square.

From the above, let $S$ is the sum of the numbers on the diagonals in a $1001$ by $1001$ spiral:

$$ \begin{align} S & = 1 + \sum_{n=1}^{500} f(n) \\ & = 1 + \sum_{n=1}^{500} (16n^{2} + 4n + 4) \end{align} $$

We can calculate naively or using formulas for sum which are mentioned at the problem 6.