1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| <?php
var_dump(asalcarpanbul(20));
function asalcarpanbul($x){ $x_guncel = $x; $asalsayilar = Array(); $carpanlar = Array(); for($i=2;$i<=$x;$i++){ $bolenadet = 0; for($m=1;$m<=$i;$m++){ if($i%$m==0) $bolenadet++; } if($bolenadet == 2){ array_push($asalsayilar, $i); } } foreach ($asalsayilar as $asal) { while($x_guncel%$asal==0){ array_push($carpanlar, $asal); $x_guncel= $x_guncel/ $asal; } }
return $carpanlar; }
?>
|