UP | HOME

Euler Problem 28

problem 28

Mathmatics method
S1 = 1
S2 = 1 + 1 * (8*2*2 - 2 + 6) * 2 / 3 = 1 + 24 = 25
Sn = S1 + (Pn-1 + n-1) + (Pn-1 + (n-1)*2) + (Pn-1 + (n-1)*3) + (Pn-1 +
(n-1)*4)
= S1 + 4 * Pn-1 + (2*n - 2)*10
= S1 + 16*{ sigma:X^2 | n-1 >= X >= 1 } + 4*{ sigma:X | n-1 >= X >= 1 }
+ 4*(n-1)
= S1 + (n-1) * (8*n*n - n + 6) * 2 /3
;;; Pn is the top-right element
P1 = 1
Pn = (2*n - 1)^2
;;; spiral number
s = 2*n - 1
;;;
for 1001 by 1001 spiral, 1001 = 2*n - 1 => n=501
thus S501 = S1 + 500 * (8*501*501 - 501 + 6) * 2 / 3