Someone found my blog by Googling Z[sqrt -n] maximal ideal and not principal. So I suppose I should prove the most general elementary theorem here, which is that Z[SQRT(n)] is never a UFD for n Q[SQRT(n)]), which is larger than Z[SQRT(n)] when n = 1 mod 4.
When n n + SQRT(n))(n – SQRT(n)) = n^2 – n = n(n-1) which is always even, but n/2 (+/-) SQRT(n)/2 is not in Z[SQRT(n)]. On the other hand, the norm inherited from Q[SQRT(n)] is still multiplicative, so any proper factor of 2 will have norm 2, which will satisfy the equation a^2 – nb^2 = 2 which has no solutions in integers when n n. If n is even, then (2, SQRT(n)) works; this ideal contains all elements of the form a + bSQRT(n) where a is even, so its quotient ring is Z/2Z, which is a field, so that it’s maximal. It’s also non-principal: a single generator must be a factor of 2, but 2 has no proper factors, and 2 itself can’t generate the element SQRT(n).
When n is odd this no longer works because SQRT(n)*SQRT(n) = n + 0*SQRT(n) and n is odd. But (2, 1+SQRT(n)) will work, because again 2 is irreducible, so there’s no proper factor of 2 to generate the ideal, and 2 can’t generate 1+SQRT(n).
Actually, there’s a more general theorem on non-unique factorization in quadratic number fields: when n Q[SQRT(n)] is a PID iff n = -1, -2, -3, -7, -11, -19, -43, -67, or -163. Proving that these nine rings of integers are PIDs is easy with the Minkowski bound; proving that all others aren’t even when n = 1 mod 4 is highly non-trivial. An even more general theorem says that for each positive integer k, there are only finitely many fields Q[SQRT(n)], n k.