Skip to content

Instantly share code, notes, and snippets.

@coder-liyang
Created December 26, 2016 04:07
Show Gist options
  • Select an option

  • Save coder-liyang/d94c36e6c30600293c4f3d6a1bb072ff to your computer and use it in GitHub Desktop.

Select an option

Save coder-liyang/d94c36e6c30600293c4f3d6a1bb072ff to your computer and use it in GitHub Desktop.
primeNumber.php
/**
* 找到一定范围内的质数/素数
* @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