I would like to know how to determine by hand whether a number is prime to help me in math contests.
-
6Have you tried google? – Dmoreno May 06 '14 at 10:42
-
Why is it important for you to do this by hand? – KCd May 06 '14 at 10:47
-
1Well, when I'm participating in a math contest XD – zscoder May 06 '14 at 10:48
-
4@zscoder If you participate to a math contest, you should know immediately that $4,294,967,297$ is not prime. – egreg May 06 '14 at 11:10
-
composite (fermat Number) – zscoder May 06 '14 at 11:13
-
3All primes except for $2$ and $3$ are of the form $6n\pm1$. – Lucian May 06 '14 at 11:26
-
There are a few techniques that can be used, but nothing at all general. It is for something that the "determine if $n$ is prime" algorithms are still an active area of research. – vonbrand May 06 '14 at 12:11
-
1@egreg my hero. As vonbrand says, this is an active area of research (and one I personally hope isn't resolved anytime soon). Much of cryptology relies on the difficulty of these problems. – Sean Allred May 07 '14 at 02:19
-
@Lucian, but the converse isn't true, which is what is needed to test here (e.g. $25$ is of the form $6n + 1$ but it's NOT prime). – Leponzo Nov 23 '21 at 20:04
-
@Leponzo: Common people usually check for primes among odd numbers; searching for them among numbers of the form $6n\pm1$ reduces the effort from half to a third. – Lucian Nov 23 '21 at 20:38
3 Answers
There's no super-fast way to determine if an arbitrary number is prime by hand. However, you can often quickly determine when a number isn't prime, which is often good enough, especially if you are only dealing with smallish numbers, as you often are in math competitions.
- If a number ends in 0, 2, 4, 5, 6 or 8 then it's not prime (except for 2 and 5)
- If the sum of the digits is a multiple of 3, then the number is not prime (except for 3)
Those two rules knock about nearly 75% of numbers.
For numbers below 100, the only false positives are $49=7^2$, $77=7\cdot 11$ and $91=7\cdot 13$ which you can learn.
Divisibility by 7
A number of the form $10x+y$ is divisible by 7 exactly when $x-2y$ is divisible by 7. This allows you to quickly reduce the size of a number until you reach a number that obviously is or isn't a multiple of 7. For example, consider $n=847 = 84\times 10 + 7$. Then $x-2y$ is $84 - 14 = 70$ which is obviously divisible by 7, so 847 is also divisible by 7.
Divisibility by 11
There is also a simple test for multiples of 11 - starting from the units place, add the first digit, subtract the next digit, add the next one and so on. If you end up with a negative number, treat it as positive. If the result is a multiple of 11, so is the original number.
For example, take $n=539$. You calculate $9-3+5=11$, which is a multiple of 11, and so 539 is a multiple of 11.
Using these rules to check for divisibility by 2, 3, 5, 7 and 11 the only false positive less than 200 is 169, which is easy to remember as it is $13^2$. The only false positives below 300 are $221=13\times 17$, $247=13\times 19$, $289=17^2$ and $299=13\times 23$.
Edit: Just for fun, here's a graph of how many false positives there are for a given upper bound. This chart shows that with four rules and a list of 13 exceptions, you can correctly find whether any number under 500 is prime or not in... probably 20-30 seconds?

- 28,955
To determine if $n$ is prime:
Find the biggest perfect square $k^2 \le n$.
Write out all the primes less than or equal to $k$.
Test if $n$ is divisible by each of said primes on your list.
If $n$ is divisible by any of the primes, $n$ is not prime.
If $n$ is divisible by none of the primes, $n$ is prime.
- 45,895
-
This is nice, but is there a faster one? (I commonly use this to determine primality) – zscoder May 06 '14 at 10:48
Edit: If you are doing it by hand read this one.
You can try [running some probabilistic primality tests, reading this article for some more info on primality tests, or reading this article on using elliptic curves.
Without any more information, it's hard to know exactly what you are looking for.
- 12,081
- 334
-
-
www-math.mit.edu/phase2/UJM/vol1/DORSEY-F.PDF there are some you can do by hand here, such as the one based on fermat's little theorem – notacat May 06 '14 at 10:55