# How can prime numbers be found mentally?

At a careers fair I was given a test to see how good I am at mental maths, And I was given multiple questions, asking whether a number was a prime.

Example question:

Which of these numbers isn't a prime?

$$257,317,287,263$$

Well, my first insentive is to check the 10s digit, so I added y to my answers and divided it by that y value, (Like $\frac{k+3}{3}$ is proved when $k$ is a multiple of $3$)

Turns out, none of the worked, not even the correct answer. (Which is $287$)

Which begs the question, how do you find a prime number mentally?, On a calculator it's as simple as displaying it's prime factors, but even then the computer inside is dividing it by $1,2,3,4,5,\ldots$ until its square root

My only guess is that there is a sequence that can be used to list a few primes, that knocks off $2$ of the candidates...

Edit: My technique was half right, rather than sticking to 3 i should have gone further up the prime numbers up to 20.

• Well in this case I would check the possible prime numbers starting with 2,5,3 and 11 because for these there are easy divisibility tests. None of these work so check for divisibility by 7 and recognize that $287=280+7$ is a multiple of $7$. – Sebastian Schoennenbeck Dec 4 '14 at 12:37
• No, you only have to divide $n$ by the prime numbers $2,3,5,7,11,13,17,19,\dots$ up to $\sqrt n$. Of the four numbers you gave, $257$ is a famous prime (one of the five known Fermat primes) and $287$ is obviously divisible by $7$. The other two take only a few seconds to test for divisibility by $2,3,5,7,11,13$ and $17$. – bof Dec 4 '14 at 12:39
• There are some simple rules that come in my mind to check whether a number is prime or not. e.g. if a number ends with $5$ then it's a multiple of $5$; if the sum of the numbers of a number sum up to a multiple of $3$ then the number is a multiple of $3$. Otherwise i subtract big multiples of numbers for instance $287-\underbrace{280}_{=7\cdot 40} =7$ so $7$ divides $287$. These are the first things that comes in my mind, but I'm sure there is plenty of other tricks. – Bman72 Dec 4 '14 at 15:14

For numbers less than $400$, you only need to test whether it has a prime factor less than $20$, that is, $2,3,5,7,11,13,17,19$. Testing for $2,3,5,11$ is easy. For the others, just do the division. It helps to subtract clear multiples of one of those primes. For instance, $317$ is not divisible by $17$ because $300=317-17$ isn't. Similarly, $263$ is not divisible by $13$ because $250=263-13$ isn't (or $3=263-260$ isn't, noting that $260=13\cdot 20$).

• I see, a test for numbers under 20 should be efficent seeing as multiple numbers can be eliminated right off the bat. For example if we take logic into account we have 3,7,11,13,17 and 19. we can take all of them from our number as a test. Given that we had 287, Taking off 7 and dividng would give us 40, thus proving it is not prime. However, given it's say 323 (19x17) it might not be so obvious – There'sASnakeInMyBoot Dec 5 '14 at 10:01
• Factoring $323$ is easy if you happen to know that $18^2=324$. – bof Dec 5 '14 at 10:09
• @bof Are you referencing another method? or the rule of the 2 squares?, (n-1)(n+1) = n^2 -1? Would that work for others such as 187 or 209? – There'sASnakeInMyBoot Dec 5 '14 at 11:46
• @bof Also, if it takes you only a few seconds to test for factoring a 3 digit number by a 2 digit number a maximum of 16 times, then i'm pretty sure you're not human – There'sASnakeInMyBoot Dec 5 '14 at 11:56
• Just the difference of two squares. Doesn't apply to $187$ or $209$ which however are obviously divisible by $11$. Your $3$-digit numbers were all less than $400$, so the only prime factors to be tested are $2,3,5,7,11,13,17,19$. Of those, $2,3,5$ and $11$ take very little time to check. So how long does it take to check $209$ for divisibility by $7,13,17,19$? Let's see. $7$? $209=210-1$, nope. $13$? $209=260-51$, nope. $17$? $209=170+39$, nope. $19$? $209=190+19$, yep! Whew, that took way longer to type than to do the arithmetic. – bof Dec 5 '14 at 12:10

If you have a 3 digit number $\rm ABC$ and $\rm AB$ is divisible by $\rm C$, then $\rm ABC$ is clearly not prime.

$${\rm ABC = AB \cdot 10 + C = C}\cdot(n\cdot 10+1)$$

$287=7\times 4\times 10+7$, so it is a multiple of 7.

If you know about quadratic reciprocity, that can sometimes be helpful. In this case, you might notice that $287$ is close to $289 = 17^{2}.$ It follows that if $p$ is a prime divisor of $287,$ then $2$ is a quadratic residue (mod $p$), so that $p \equiv \pm 1$ (mod $8$). The first prime congruent to $1$ (mod $8$) is $17$, so no prime divisor of $287$ is congruent to $1$ (mod $8$). The only prime congruent to $7$ (mod $8$) which is small enough to have a chance of dividing $287$ is $7$ itself, which does indeed work. In this case, the strategy is not quicker than trial and error, but for larger numbers, quadratic reciprocity can prune possibilities.