Computation Workshop Solution Checker

A Spirals Diagonals

Let \(n\) be a positive integer. The numbers from \(1\) to \(n^2\) are arranged into an \(n \times n\) grid in a spiral pattern, starting from the top-left corner. Let \(D(n)\) denote the sum of the diagonals of this grid.

Example: If \(n=3\) then the grid is

123
894
765

And so \(D(3) = 1+3+5+7+9 = 25\).

Another Example: If \(n=4\) then the grid is

1234
1213145
1116156
10987

And so \(D(4) = 1+4+7+10+13+14+15+16 = 80\).

Part A Find \(D(12)\)
Part B Find \(D(12345)\)
Part C Find \(D(123456)\)