We wish to find the set of natural numbers that cannot be expressed as a difference between a square and a prime. 


e.g.


$1 = 2^2 - 3$


$2 = 3^2 - 7$


$3 = 4^2 - 13$


and so on.


The smallest such number is $16$. The proof that $16$ cannot be expressed as a difference of a square and a prime:


Let $r^2 - p = 16$ for natural number $r$ and prime $p$


$\implies (r-4)(r+4) = p$


$\implies r-4 = 1$ since the two factors of $p$ are $p$ and $1$


$\implies r = 5$ but then $r + 4 = 9$ which is not a prime.


In general, this is true for all $n^2$ where $2n + 1$ is composite since the same reasoning applies. Therefore $49, 100, 144, 169..$ can be seen to belong to this set.


The question is whether all the numbers which cannot be expressed like this are of this form i.e. $n^2$ where $2n + 1$ is composite. A brute force search shows that this holds true for numbers less than 10000.



Natural numbers that cannot be expressed as a difference between a square and a prime?
We have a representation $m=x^2-p$ where $m$ and $x$ are positive integers and $p$ is a prime if and only if there is a prime of the form $x^2-m$. Little is known about primes of the form $x^2-m$; it has not been proved for any fixed value of $m$ that there are infinitely many such primes. However, [Bunyakovsky's conjecture](http://en.wikipedia.org/wiki/Bunyakovsky_conjecture) (or in fact a special case of it) would imply that $x^2-m$ is prime for infinitely many $x$ unless $m$ is a square. So, if we assume this conjecture, every non-square is the difference of a square and a prime. And if $m=n^2$ is a square, then clearly the representation is possible if and only if $2n+1$ is a prime.


It is of course a weaker claim that the sequence $x^2-m$ contains one prime than infinitely many, but proving this weaker statement for all non-squares $m$ might be almost as hard as proving the stronger statement. For example, proving Dirichlet's theorem about primes in arithmetic progressions is esentially as hard as showing that the sequence $an+b$ contains at least one prime for all coprime $a$ and $b$. 


