Starting with 1 and spiralling clockwise, a 5 by 5 spiral is formed as follows: 21 22 23 24 25 20 7 8 9 10 19 6 1 2 11 18 5 4 3 12 17 16 15 14 13 The sum of the diagonals is 1 + 3 + 5 + 7 + 9 + 13 + 17 + 21 + 25 = 101. Given n (odd), find the sum of the numbers on both diagonals in an n x n spiral.
Example 1:
Example 2:
Example 3:
Constraints:
1 <= n <= 10^6, n is odd
Tags:
