TITLE: Smith normal form for specialized matrices
QUESTION [6 upvotes]: Consider an $n\times n$ matrix $M_n$ where the sequence $1,2,3,\dots,n^2$ forms a clock-wise spiral, in that given order. For example,
$$M_4=\begin{bmatrix} 1&2&3&4\\ 12&13&14&5\\ 11&16&15&6 \\ 10&9&8&7 \end{bmatrix} \qquad \text{and} \qquad
M_5=\begin{bmatrix} 1&2&3&4&5\\ 16&17&18&19&6 \\ 15&24&25&20&7 \\
14&23&22&21&8 \\ 13&12&11&10&9
\end{bmatrix}.$$ 

Question. What are the diagonal entries in the Smith normal form of the matrix $M_n$, over $\mathbb{Z}$?

REPLY [5 votes]: not a complete answer, but too long for a comment:
some experimentation$^*$ suggests that the diagonal entries of the diagonal matrix $S_n$ in the integer decomposition $M_n=U_nS_nV_n$, with $U_n,V_n$ unimodular, have the following form for $n> 2$:
$${\rm diag}\,S_n=1,1,2,2,2,\cdots 2,2,2,\{Z_n\},c_n$$ 
where the $\cdots$ indicate padding to length $n$ with a string of $2$'s and $\{Z_n\}$ is a string of integers given by
$$\{Z_n\}=\emptyset\;\;{\rm for}\;\;n\leq 5,$$
$$\{Z_n\}=\{6\},\{30\},\{6\},\{6,30\},\{6,30\}\;\;{\rm for}\;\;n=6,7,8,9,10,$$
$$\{Z_n\}=\{6,30\},\{6,30,210\},\{6,6,210\},\{6,30,210\},\{6,6,30,6930\}\;\;{\rm for}\;\;n=11,12,13,14,15,$$
$$\{Z_n\}=\{6,6,30,630\},\{6,30,30,630\},\{6,6,6,30,6930\},\{6,6,30,210,6930\},\{6,6,30,210,6930\}\;\;{\rm for}\;\;n=16,17,18,19,20,$$
$$\{Z_n\}=\{6,6,6,30,210,90090\},\{6,6,30,30,210,90090\},\{6,6,6,30,210,1531530\},\{6,6,6,30,30,630,90090\},\{6,6,6,30,30,630,90090\}\;\;{\rm for}\;\;n=21,22,23,24,25,$$
and so on. Unfortunately, I have been unable to detect a pattern in this sequence.
The final diagonal entry of $S_n$ is 
$$c_n=\frac{2^{3-n}|{\rm det}\,M_n|}{\prod_{i}\tfrac{1}{2}(Z_n)_i}$$ following from the formula OEIS A023999 for the determinant of a spiral matrix: 
$$|{\rm det}\,M_n|={\rm det}\, S_n=(3n-1) \frac{ (2n-3)!}{(n-2)!}$$

$^*$ if you would like to experiment further with spiral matrices, here are a few lines of relevant Mathematica code; I am intrigued by this $Z_n$ pattern, what is the logic behind it?