Also known prime number prime number. Is a natural number greater than 1, except 1 and itself, the other can not be called a natural number divisible prime number;
Otherwise known as composite numbers: The basic idea of judgment
In general the field, for positive integer n, if all removed by an integer between 2 and are not divisible, then n is a prime number.
Prime number not less than 2 is not divisible by the number other than 1 and is itself
1 $arr = array(); 2 3 for ($i=2; $i<=100; $i++){ 4 $str = false; 5 for ($j=2; $i<=4 ? $j<$i : $j<=$i/2; $j++){ 6 7 if ($i % $j == 0){ 8 $str = false; 9 break ; 10 }else{ 11 12 $str = true; 13 14 } 15 16 } 17 18 if($str){ 19 array_push($arr,$i); 20 } 21 22 } 23 echo print_r($arr);
PHP
$arr = array(); for ($i=2; $i<=100; $i++){ $str = false; for ($j=2; $i<=4 ? $j<$i : $j<=$i/2; $j++){ if ($i % $j == 0){ $str = false; break ; }else{ $str = true; } } if($str){ array_push($arr,$i); } } echo print_r($arr);