php gets the number within 89 that is divisible by 1 and itself. I can’t find a clue about this, so I’m looking for methods and guidance
php gets the number within 89 that is divisible by 1 and itself. I can’t find a clue about this, so I’m looking for methods and guidance
I have encountered this problem. I remember I encountered it when I went to a company for an interview. I specially compiled it for you to refer to and it will be easy to understand.
<code>final function getPrimesNumber($number) { $primes = array (); for($i = 1; $i < $number; $i ++) { for($j = 2; $j < $i; $j ++) { if ($i % $j == 0) { continue 2; } } $primes [] = $i; } return $primes; }</code>
It isonly
a number that can be divisible by 1 and itself, that is, a prime number, right?
<code>$max = 89; for($i = 1; $i <= $max; $i++) { $k = 0; for($j = 1; $j < $i; $j++) { if($i % $j == 0) { $k++; } } if($k == 1) { echo $i . '\n'; } }</code>