31 lines
611 B
PHP
31 lines
611 B
PHP
|
<?php
|
||
|
|
||
|
|
||
|
function getNextPrimeBdays(int $age, int $countNextBdays,?int $ageLimit = null):array{
|
||
|
if ($ageLimit === null){
|
||
|
$ageLimit = 100;
|
||
|
}
|
||
|
$out = [];
|
||
|
while($countNextBdays > 0) {
|
||
|
for ($age = 32; $age <= $ageLimit; $age++) {
|
||
|
$primenum = true;
|
||
|
for($denominator = 2; $denominator <= $age/2; $denominator++) {
|
||
|
if(((float)$age % (float)$denominator) == 0.0) {
|
||
|
$primenum = false;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
if ((bool)$primenum) {
|
||
|
$out[] = $age;
|
||
|
$countNextBdays--;
|
||
|
if($countNextBdays == 0){
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|
||
|
return $out;
|
||
|
}
|
||
|
|
||
|
echo json_encode(getNextPrimeBdays(32,10));
|