源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

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

  • 时间:2022-06-25 06:42 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:php 求质素(素数) 的实现代码
[u]复制代码[/u] 代码如下:
<?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,$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"; } } ?> <?php echo 'check prime<br/>'; 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<br/>'; } else { echo 'false<br/>'; } } $sw->stop(); $sw->show(true); ?>
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部