ホームページ  >  記事  >  バックエンド開発  >  素数を見つけるための PHP 実装コード_PHP チュートリアル

素数を見つけるための PHP 実装コード_PHP チュートリアル

WBOY
WBOYオリジナル
2016-07-21 15:30:53842ブラウズ

复制代码代码如下:

class timer
{
var $time_start;
var $time_end;

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

関数タイマー()
{
$this->__construct();
}

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

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

関数 show($output = false)
{
$total = $this->time_end - $this->time_start;
if ($output) {
echo $total," 秒";
true を返します。
}
$total を返します。" 秒";
}

}
?>
echo 'チェックプライム
';
関数 IsPrime($i)
{
if($i<2)
{
return false;
}
//var $iterator;
for($iterator = 2 ; $iterator <= sqrt($i) ; $iterator++)
{
if($i % $iterator==0)
{
return false;
}
}
true を返します。
}

$sw=新しいタイマー();
$sw->start();
for($j=1;$j<100;$j++)
{
if(IsPrime($j))
{
echo 'true
';
}
else
{
echo 'false
';
}
}
$sw->stop();
$sw->show(true);

?>

www.bkjia.comtru​​ehttp://www.bkjia.com/PHPjc/323176.html技術記事例: ?php class timer { var $time_start; var $time_end; function __construct() { $今回_start = 0; $今回の終了 = 0; } 関数 timer() { $this-__constr...
声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。