"Whether you choose to program or just use pen and paper, there's a lot of different ways to tackle this problem. Here's one approach.\n",
"\n",
"If we have an $n \\times n$ spiral (note that $n$ must be odd!), it's pretty easy to get a formula for just the sum of the corners. The top right corner will always be $n^2$, and since it's an $n \\times n$ spiral (as mentioned one sentence ago), the top left corner will just be $n^2 - (n - 1)$. We can continue subtracting $n-1$ to get the values of the other corners. Adding these up, we get\n",
"Of course, we want the sums of the *diagonals*, not just the outermost corners. We can think about this as getting the sum of the corners of the $n \\times n$ spiral, plus the sum of the corners of the $(n-2) \\times (n-2)$ spiral one layer deeper, and so on until we reach the 1 at the center.\n",
"Now we can apply [summation identities](https://en.wikipedia.org/wiki/Summation) (including the return of triangular numbers and square pyramidal numbers from [problem 6](https://projecteuler.net/problem=6)) to get a closed formula:\n",
"Side note: this practice of writing the natural numbers in a spiral, combined with marking the prime numbers, has been coined the [Ulam spiral](https://en.wikipedia.org/wiki/Ulam_spiral). Somewhat interestingly, lots of primes appear in vertical, horizontal, and diagonal lines when laid out this way.\n",
"* Numbers on diagonals: [A200975](https://oeis.org/A200975)\n",
"\n",
"#### Copyright (C) 2025 filifa\n",
"\n",
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."