Waste less time on Facebook — follow Brilliant.
×

Prime Number Testing

Friends, what do you suggest will be quickest way to test whether a number is prime or not?? Testing for forms 4k+-1 or 6k+-1 is useful to test if it is not prime,but doesn't ensure sure results for a number being prime...

Note by Paramjit Singh
4 years, 6 months ago

No vote yet
3 votes

Comments

Sort by:

Top Newest

There is a faster method. Its called miller rabin primality test, and is much much faster than trial division. But it can't be used if you're looking to check primes manually.

With computers, miller rabin primality test is very fast You can read more about it here

Its main advantage is that you don't have to go about calculating primes uptill \(\sqrt{n}\), and then checking each. Harshit Kapur · 4 years, 6 months ago

Log in to reply

@Harshit Kapur For programming however,the miller rabin primality test is indeed a cool algorithm... Paramjit Singh · 4 years, 6 months ago

Log in to reply

@Harshit Kapur Well,if you go for programming then finding primes,& then storing them in an array is a better way indeed...& many programming techniques are available,& the computer has to work....I'm looking for the mathematical interpretation,if any... Paramjit Singh · 4 years, 6 months ago

Log in to reply

@Harshit Kapur Unfortunately this test is not deterministic... Lawrence Sun · 4 years, 6 months ago

Log in to reply

@Lawrence Sun But it can be made deterministic. Read here

And it doesn't take too much to do so. Here is an implementation in python.I haven't added support for too big numbers, but it can be done easily. Harshit Kapur · 4 years, 6 months ago

Log in to reply

To test whether if a number is a prime, we just need to test whether if the number, \(n\), is divisible by any prime \(\leq \sqrt{n}\).

Example : \(103\) is a prime since \(2, 3, 5, 7 \nmid 103\). On the other hand, \(91\) is since \(7 \mid 91\).

This works since if a number is composite, it must have a prime factor \(\leq \sqrt{n}\).

Hope this helps! :) Zi Song Yeoh · 4 years, 6 months ago

Log in to reply

@Zi Song Yeoh Wouldn't a prime number sieve be faster for the smaller primes? Tan Li Xuan · 4 years, 6 months ago

Log in to reply

@Zi Song Yeoh Thanks for your suggestion,I knew that the largest number which can divide a composite is it's square root...however I'm looking for quick eye techniques,does anyone know one??? Paramjit Singh · 4 years, 6 months ago

Log in to reply

@Paramjit Singh just divisibility rules can help you there Harshit Kapur · 4 years, 6 months ago

Log in to reply

@Paramjit Singh shouldn't that be largest prime number? Tan Li Xuan · 4 years, 6 months ago

Log in to reply

×

Problem Loading...

Note Loading...

Set Loading...