CT095

Number Spiral Diagonals

EasyAcceptance: 0.0%

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:

Input: 5
Output: 101

Example 2:

Input: 1001
Output: 669171001

Example 3:

Input: 101
Output: 692101

Constraints:

1 <= n <= 10^6, n is odd

Tags:

math spiral patterns
Loading...
Test Cases:No test cases
No test cases available.