The Student Room Group

How to prove a number is prime (division method)

Do you divide by just 2,3,5 then 7 or do you have to go up to prime before the square root? For either why do you do this?
Up to the prime before the square root.

For example if you were to divide 143 only by 2, 3, 5 and 7, you wouldn't see that 143 is in fact divisible by 11 and 13 and so is not a prime.
Indeed, the simplest primality test is to check if your number nn divisible by any mm where 2mn2 \leqslant m \leqslant \sqrt{n}

People have developed other tests but that's the one that everyone uses. :yep:
Wouldn't doing something like a Fermat's little thereom primality test be much more efficient for larger primes?

Posted from TSR Mobile
Reply 4
Original post by TheOtherSide.
Up to the prime before the square root.

For example if you were to divide 143 only by 2, 3, 5 and 7, you wouldn't see that 143 is in fact divisible by 11 and 13 and so is not a prime.


Original post by Indeterminate
Indeed, the simplest primality test is to check if your number nn divisible by any mm where 2mn2 \leqslant m \leqslant \sqrt{n}

People have developed other tests but that's the one that everyone uses. :yep:



Thank you! Why is it up to the square root and not further?

Original post by BobBobson
Wouldn't doing something like a Fermat's little thereom primality test be much more efficient for larger primes?

Posted from TSR Mobile

Not sure I haven't come across it I'm a yr13 student
Original post by swagmister
Thank you! Why is it up to the square root and not further?


Observe that if nn is not prime, then it can be written as n=ab n = ab for some aa and bb

At least one of these must be n\leqslant \sqrt{n} otherwise ab>nab > n
Reply 6
Original post by Indeterminate
Observe that if nn is not prime, then it can be written as n=ab n = ab for some aa and bb

At least one of these must be n\leqslant \sqrt{n} otherwise ab>nab > n

Ah okay thanks!
Original post by Indeterminate
Indeed, the simplest primality test is to check if your number nn divisible by any mm where 2mn2 \leqslant m \leqslant \sqrt{n}

People have developed other tests but that's the one that everyone uses. :yep:
Well, not really. Almost anyone using this approach is actually going to check "is n divisible by 2?". If not, check for every odd m with 3mn3 \leqslant m \leqslant \sqrt{n} , which is half the work.

Of course, this method is hopeless for primality checkijng of large primes.


Original post by BobBobson
Wouldn't doing something like a Fermat's little thereom primality test be much more efficient for larger primes?
Unfortunately, this doesn't work; there are numbers that pass Flt for all bases but are not prime. https://en.wikipedia.org/wiki/Carmichael_number

A somewhat related test that does "work" is Miller-Rabin. This gives absolute proof if tested with enough bases, with computational complexity O((log n)^4) (assuming Generalized Riemann Hypothesis). But for a composite number C, each test to a random base has at least (3/4) chance (*) of showing C is composite, and so the chance of C passing n tests is (3/4)^n. So in practice doing 50 or so tests on C gives you a scenario where if it somehow turned out C was composite, it's more likely something is wrong with the computer than that the tests have failed.

(*) in practice it's a lot higher. Using the first 6 primes as test-bases is enough to exclude all non-pirmes under 3 trillion.

Quite recently, an unconditional polynomial time (i.e. polynomial in number of digits of n) algorithm was found (known as the AKS primality test; the initial implementation was O((log n)^12 and this has been improved to O((log n)^6).

In practice I think people use Miller-Rabin variants for finding primes for RSA encryption et. al.

There are also specialised tests for numbers of particular forms, this is why we're able to find Mersenne primes (of form 2^n - 1) with much greater efficiency than general primes of similar size.
(edited 7 years ago)

Quick Reply

Latest