Created
December 26, 2016 04:07
-
-
Save coder-liyang/d94c36e6c30600293c4f3d6a1bb072ff to your computer and use it in GitHub Desktop.
primeNumber.php
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
| /** | |
| * 找到一定范围内的质数/素数 | |
| * @param int $max 质数范围 | |
| * @return array | |
| */ | |
| function primeNumber($max) | |
| { | |
| $max = (int)$max; | |
| $result = array(); | |
| $i = 1; | |
| do{ | |
| $k = 0; | |
| $i++; | |
| $j = 1; | |
| do { | |
| $j++; | |
| if ($i%$j == 0) { | |
| $k++; | |
| } | |
| } while ($j < $i); | |
| if ($k == 1) { | |
| $result[] = $i; | |
| } | |
| } while ($i < $max); | |
| return $result; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment