欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

php 求质素(素数) 的实现代码_PHP教程

程序员文章站 2022-06-08 10:36:00
...
复制代码 代码如下:

class timer
{
var $time_start;
var $time_end;

function __construct()
{
$this->time_start = 0;
$this->time_end = 0;
}

function timer()
{
$this->__construct();
}

function start()
{
list($usec,$sec) = explode(" ",microtime());
$this->time_start = (float)$usec + (float)$sec;
}

function stop()
{
list($usec,$sec) = explode(" ",microtime());
$this->time_end = (float)$usec + (float)$sec;
}

function show($output = false)
{
$total = $this->time_end - $this->time_start;
if ($output) {
echo $total," sec";
return true;
}
return $total." sec";
}

}
?>
echo 'check prime
';
function IsPrime($i)
{
if($i{
return false;
}
//var $iterator;
for($iterator = 2 ; $iterator {
if($i % $iterator==0)
{
return false;
}
}
return true;
}

$sw=new timer();
$sw->start();
for($j=1;$j{
if(IsPrime($j))
{
echo 'true
';
}
else
{
echo 'false
';
}
}
$sw->stop();
$sw->show(true);

?>

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/323176.htmlTechArticle复制代码 代码如下: ?php class timer { var $time_start; var $time_end; function __construct() { $this-time_start = 0; $this-time_end = 0; } function timer() { $this-__constr...