Created
September 20, 2017 08:00
-
-
Save HoangPV/63e88a6bbdfd1691cd21d51e5b0394bd to your computer and use it in GitHub Desktop.
checks if a number is prime
This file contains hidden or 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 | |
/** | |
* checks if a number is prime | |
* | |
* @return bool | |
* @author Phan Vu Hoang <[email protected]> | |
*/ | |
function la_snt( $n ) { | |
if($n < 2) return false; | |
if($n == 2) return true; | |
if($n%2==0) return false; | |
for ($i=3; $i <$n-1 ; $i+=2) { | |
if($n%$i==0) return false; | |
} | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment