微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

php 求质素素数 的实现代码

<div class="codetitle"><a style="CURSOR: pointer" data="61126" class="copybut" id="copybut61126" onclick="doCopy('code61126')"> 代码如下:

<div class="codebody" id="code61126">
<?PHP
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,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";
} }
?>
<?PHP
echo 'check prime
';
function IsPrime($i)
{
if($i<2)
{
return false;
}
//var $iterator;
for($iterator = 2 ; $iterator <= sqrt($i) ; $iterator++)
{
if($i % $iterator==0)
{
return false;
}
}
return true;
} $sw=new timer();
$sw->start();
for($j=1;$j<100;$j++)
{
if(IsPrime($j))
{
echo 'true
';
}
else
{
echo 'false
';
}
}
$sw->stop();
$sw->show(true); ?>

原文地址:https://www.jb51.cc/php/28074.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐