测试php计算1-500000中有多少个质数耗时脚本

]#vim testphp.php

<?php
$n = 0;
$start = 1;
$end = 500000;
for($num = $start; $num <= $end; $num++) {
    if ( $num == 1 ) continue;
    for ($i = 2; $i <= sqrt($num); $i++) {
        if ($num % $i == 0) continue 2;
    }
    $n++;
}
print_R($n."\n");

]#time php testphp.php

猜你喜欢

转载自blog.csdn.net/qq_36586867/article/details/81451796