标题: [超优化,100000以内1s]关于求质数,我的看法
时间: 2014-04-09
<?php
$btime=microtime(true);
$begin=2;
$end=100000;
$num=array_fill(2,($end-1),0);
$a=2;
$b=$end/2;
while($a<=$b){
$s=$end/$a;
$num[$a]=1;
for($c=2;$c<=$s;$c-=-1){
unset($num[$a*$c]);
}
foreach($num as $key => $val){
if($val==0){
$a=$key; break;
}
}
}
$znum=0;
for($d=2;$d<$begin;$d-=-1){
unset($num[$d]);
}
$znum=count($num);
echo $znum;
$etime=microtime(true);
echo("<br />".($etime-$btime));
?>
测试[YH空间]:http://app2.nkzx.tk/z.php『回复列表(10|隐藏机器人聊天)』