Checking Whether a Number is Prime.

Posted on the 26 May 2021 by Markwadsworth @Mark_Wadsworth

You can't really check whether a number is prime, you can only check whether it divides by a prime number smaller than the square root of the original number and rule it out if it does. So it's a question of ruling out as many as possible as quickly as possible.
First, you rule out even numbers and numbers ending in 5 (apart from 2 and 5).
The next obvious/easy thing to do is to add the digits and see if they add up to 3, if they do, the number divides by three i.e. 291 = 2 + 9 + 1 = 12 (unless you start with 3, which itself is prime).

But I've watched another couple of maths videos on YouTube, and what they boil down to is that there is a better test that helps you rule out more numbers. The test is - divide the original number by thirty and just look at the remainder, or take "number mod 30" if you are using a scientific calculator.
If the remainder is not a prime number, the original number is not prime. If the remainder is prime (or ends in 1, even though the number 1 itself is officially not a prime number) and the original number is less than 300, there is a two-thirds chance the original number is prime. The chance of it being prime is slightly better than 50% for numbers up to 1,500. That percentage drifts downwards, the larger the number is. So if the original number was above 1,500, you might as well just assume it is not prime, even if the remainder is prime.
If the original number passes the second test and you want to improve your chances of getting it right, you have to do the long hard slog with divisibility tests, and check if it divides by 7, 11, 13...
I hope this comes in handy next time you are in a pub quiz. I can't think of many other uses for such trivia.