# $x^2 - (x - 1)$ is prime?

So whenever I square any number and subtract previous number of the original I always end up with a prime number. Why is it so? Let's say a number $x$ is squared and $x - 1$ is subtracted from it the result would be prime.

• $25-4=21$, $64-7=57$... – krirkrirk Feb 25 '18 at 20:31
• Before you ever assume something, maybe you should go through a few values of $x$ before you even start typing on Math SE – VortexYT Feb 25 '18 at 20:34
• $10^2-9=100-9=91=13\cdot 7$ – G Tony Jacobs Feb 25 '18 at 20:36
• If $x\equiv 2 \pmod(3),$ then $x^x-x+1$ is divisible by $3,$ so at least one-third of the examples you try will fail. You can't have tried very many. – saulspatz Feb 25 '18 at 20:36
• Go on Wolfram Alpha and put in Select[Table[n^2 - (n - 1), {n, 50}], Not[PrimeQ[#]] &] for plenty more counterexamples. – Lisa Feb 25 '18 at 21:41

Maybe you've gotten lucky and only tested numbers drawn from Sloane's A055494:

A055494 Numbers $n$ such that $n^2 - n + 1$ is prime. ... 2, 3, 4, 6, 7, 9, 13, 15, 16, 18, 21, 22, 25, 28, 34, 39, 42, 51, 55, 58, 60, 63, 67, 70, 72, 76, 78, 79, 81, 90, 91, 100, 102, 106, 111, 112, 118, 120, 132, 139, 142, 144, 148, 151, 154, 156, 162, 163, 165, 168, 169, 174, 177, 189, 190, 193, 195, 204, 207, 210, 216

Obviously $n^2 - n$ is a multiple of $n$. But $n^2 - n + 1$ is coprime to $n$, meaning that it has no prime factors in common with $n$. So it will sometimes happen that $n^2 - n + 1$ is actually itself prime.

For example, $8^2 - 8 + 1 = 57 = 3 \times 19$. So 8 is a power of 2, while 57 is an odd number, the product of two odd primes. 57 is not prime, but it still has no prime factors in common with 8.

Compare that to 9, which gives us $9^2 - 9 + 1 = 73$, which is indeed prime.

$5^2 - 4 = 25 - 4 = 21 = 7 \cdot 3$.

Note that

$$x^2-(x-1)=(x+\sqrt{x-1})(x-\sqrt{x-1})$$

thus for counterexamples it suffices that $x-1$ is a square.