加入收藏 | 设为首页 | 会员中心 | 我要投稿 安卓应用网 (https://www.0791zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > PHP > 正文

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

发布时间:2020-05-24 20:10:05 所属栏目:PHP 来源:互联网
导读: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); ?>

(编辑:安卓应用网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读