TITLE: The modular arithmetic contradiction trick for Diophantine equations
QUESTION [19 upvotes]: It is a slick, and seemingly ad-hoc, technique often used to prove that a Diophantine equation has no solutions.
The equation $f(x_1,\ldots, x_k)=0$, with variables $x_i\in\mathbb{Z}$ and some elementary function $f$, is taken modulo some ingeniously chosen $n\in\mathbb{Z}^+$. Then by evaluating $f$ on the $k^n$ possible $k$-tuples $(x_1,\ldots,x_k)$ of residues modulo $n$, it is shown that $0$ is achieved in no case. Thus no solution exists in $\mathbb{Z}$ either.
A traditional classroom example is $x^2+y^2-3z^2=0$. Assume $\gcd(x,y)=1$ without loss of generality, and use modulo $3$.
The trouble is in coming up with the brilliant $n$. An example of a good heuristic principle is choosing modulo $20$ if there are powers of $4$ as, out of to $20$ possible residues, the only quartic residues are $0,1,5,16$. Are there similar mods for other powers?
In general, has there been any work done on an objective way of finding $n$? Perhaps good heuristics, if nothing else? Restrict $f$ to some non-trivial case, say certain polynomials of given degree, if needed. Paper references would be nice.

REPLY [16 votes]: Alex says in his answer that for a polynomial that is an integral or rational quadratic form, congruence conditions explain completely when it has no rational zeros (other than $(0,\dots,0)$). Congruence conditions need not be sufficient to explain a lack of integral  solutions in some other situations. 

Consider $2x^2 + 7y^2 = 1$. It has no integral solutions, but has the rational solutions $(1/3,1/3)$ and $(3/5,1/5)$.  Because the denominators in the two solutions are relatively prime, they can be used to produce solutions to $2x^2 + 7y^2 \equiv 1 \bmod m$ for any $m \geq 2$. (See Diophantine equation with no integer solutions, but with solutions modulo every integer for more examples in this direction.)
Consider a Mordell equation $y^2=x^3+k$ with $k$ a nonzero integer. Depending on $k$ there may or may not be an integral solution (e.g., there is if $k = 1$ and there is not if $k = 6$), but you can't rule out the possibility of an integral solution using modular arithmetic alone since $y^2 \equiv x^3 + k \bmod m$ has a solution for every $m \geq 2$.
It suffices by the Chinese remainder theorem to show $y^2 \equiv x^3 + k \bmod p^r$ is solvable for every prime power $p^r$, or what amounts to the same thing, there is a $p$-adic integer solution for every prime $p$. There is a 2-adic integer solution $(x,k+1)$ for some $x$ and a 3-adic integer solution $(1−k,y)$ for some $y$. In the 5-adic integers there is a solution $(0,y)$ if $k \equiv 1, 4 \bmod 5$, $(1,y)$ if $k \equiv 0, 3 \bmod 5$, and $(-1,y)$ if $k \equiv 2 \bmod 5$. In the 7-adic integers there is a solution $(0,y)$ if $k≡1,2,4 \bmod 7$, $(1,y)$ if $k≡0,3 \bmod 7$, $(−1,y)$ if $k≡5 \bmod 7$, and $(x,0)$ if $k ≡ 6 \bmod 7$. For $p \geq 11$, let $N_p$ be the number of mod $p$ solutions to $y^2 \equiv x^3 + k \bmod p$, so $N_p=p+S_p$ where $S_p=0$ if $p|k$ and $|S_p| \leq 2\sqrt{p}$ by the Hasse bound if $(p,k)=1$. Then $N_p \geq 4$, so there is a solution to $y_0^2 \equiv x_0^3 + k \bmod p$ where $y_0 \not\equiv 0 \bmod p$, and this solution lifts $p$-adically to $(x_0,y)$ for some $p$-adic integer $y$.