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.

I think my determinant formulae are correct but I made an error coding the even one. I believe you also copied my error:

line 50 :Det=D^Xn-Xi*D+int(Xi-1)

should be

:Det=D^Xn-Xi*D^2+int(Xi-1)

I think this makes the case n=4 a square! Do you agree?

(Otherwise, without a solution, where did 2018 come from :-) )

Thanks for conquering the roundoff question.