PHP Classes

Suggestion with checkIfPrime method

Recommend this page to a friend!

      PHP Prime Numbers Generator  >  All threads  >  Suggestion with checkIfPrime method  >  (Un) Subscribe thread alerts  
Subject:Suggestion with checkIfPrime method
Summary:More sufficient way
Messages:2
Author:Augustinas Malinauskas
Date:2013-11-02 13:35:38
Update:2013-11-03 21:36:20
 

  1. Suggestion with checkIfPrime method   Reply   Report abuse  
Picture of Augustinas Malinauskas Augustinas Malinauskas - 2013-11-02 13:35:38
Your checkIfPrime() method checks if $this->_number is divisible by all the numbers from 3 up to $this->_number.

However it is only necessary to check the divisibility up to (and including) sqrt($this->_number). This is standard result of Number Theory and a little explained here:

stackoverflow.com/questions/5811151 ...

  2. Re: Suggestion with checkIfPrime method   Reply   Report abuse  
Picture of Assaad Youssef Abou Rached Assaad Youssef Abou Rached - 2013-11-03 21:36:20 - In reply to message 1 from Augustinas Malinauskas
Hi Augustinas,

Thanks for your valuable feedback. I don't if you checked the new implementation, I enhanced the algorithm and made it faster by x25 times.

I am working on a better way for huge numbers (20 digits and above). Currently I'm looking for a pattern between 2 and 1000.

Thanks again mate