Created
October 14, 2015 20:22
-
-
Save oscarnevarezleal/d48d0c73e4d4fb1edc93 to your computer and use it in GitHub Desktop.
prime numbers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @param $number | |
* @return bool | |
*/ | |
function is_prime($number) | |
{ | |
if ($number < 2) { | |
return false; | |
} | |
if ($number === 2) | |
return true; | |
if ($number % 2 === 0) | |
return false; | |
$sqrt = ceil(sqrt($number)); | |
for ($i = 3; $sqrt < $i; $i += 2) { | |
if ($number % $i === 0) { | |
return false; | |
} | |
} | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment