For each positive integer n, let Mn be the square matrix (nxn) where each diagonal entry is 2018, and every other entry is 1.

Determine the smallest positive integer n (if any) for which the value

of det(Mn) is a perfect square.

(In reply to

re: how about 2019 instead of 2018? by Daniel)

Yes, your analysis is very nice indeed! That det = (d-1)^(n-1) (d-1+n) where d is the diagonal number, seems correct. While I was not able to derive it, it checked it against Wolfram to n=7. I guessing the derivation involves a recursive procedure that takes the nxn matrix through row reduction down to a simple form of mostly zeros and then only a smaller (signed minor) matrix (2x2?) needs its det. (I had to dust off my ancient Schaum's Lin. Alg. notes to recall the algorithms). But, how did you get it? Thanks.

The 2017 (2017 + n) argument (divisible by 2017) is nice too, and true even if 2017 did not happen to be prime.

BTW, here are fun facts about 2017:

https://www.iafrikan.com/2017/01/01/hello-2017-more-than-prime-number/

Also, Wolfram confirmed det M7(2019) is a square (my consolation prize.) I will celebrate next year.

Thanks! - Steve Lord