TITLE: A Diophantine equation solved when N is not a square?
QUESTION [15 upvotes]: In the following all variables are assumed to be integers.
It is easy to write a Diophantine equation which has solutions only when $N$ is a square. i.e.
$$N=A^2$$
It's trivial to write a Diophantine equation which has solutions if and only if $N$ is divisible by 4:
$$N = 4A$$
Also it is fairly easy to write a Diophantine which has solutions if and only if $N$ is not divisible by 4:
$$(N-4A-1)(N-4A-2)(N-4A-3)=0$$
But how about a Diophantine equation which has solutions if and only if $N$ is not a square number?
(sum, product and minus only can be used).

REPLY [8 votes]: Pell's equation $$X^2-NY^2=1$$
has a solution in integers other than the trivial $(\pm1, 0)$ if and only if $N$ is not a square.
To express that $X^2 \neq 1$, one can add one of the equations from What is the simplest Diophantine equation equivalent to N is not zero?
that is, one of:

$Z=1+A^2+B^2+C^2+D^2$
$AZ=(2B+1)(3B+1)$
$AZ=7+B^2+BC+C^2$

where $Z=X^2-1$

Edit: as in Misha Lavrov's answer, this only characterizes positive non-squares.