<?php
$time_start=microtime(true);
$num = 100;
$arrR = array();
for($n=1; $n<=$num; $n++){
$arrR[] = $n;
}
for($i=1; $i<count($arrR)-1; $i++){
//var_dump($arrR);
//echo '<p style="color:red;">'.$i.'/'.$arrR[$i].'</p>';
for($j=count($arrR)-1; $j>$i; $j--){
//echo '<p style="color:green;">'.$j.'/'.$arrR[$j].'</p>';
//$arrR = $arrR;
if($arrR[$j] % $arrR[$i] == 0){
//echo $j.'<br />';
//echo '<p style="color:blue;">'.$j.'/'.$arrR[$j].'</p>';
unset($arrR[$j]);
}
}
sort($arrR);
}
array_shift($arrR);
//var_dump($arrR);
echo implode(',', $arrR);
$time_end=microtime(true);
$c=$time_end-$time_start;
echo "<p>Time cost ".$c." seconds</p>";
//2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97
//Time cost 0.00037503242492676 seconds
find prime numbers
最新推荐文章于 2021-02-24 07:51:43 发布