php 求质素(素数) 用法示例
内容摘要
这篇文章主要为大家详细介绍了php 求质素(素数) 用法示例,具有一定的参考价值,可以用来参考一下。
对此感兴趣的朋友,看看idc笔记做的技术笔记!
代码如下:
<?php
class timer
对此感兴趣的朋友,看看idc笔记做的技术笔记!
代码如下:
<?php
class timer
文章正文
这篇文章主要为大家详细介绍了php 求质素(素数) 用法示例,具有一定的参考价值,可以用来参考一下。
对此感兴趣的朋友,看看idc笔记做的技术笔记!
代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | <code> <?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); ?> </code> |
注:关于php 求质素(素数) 用法示例的内容就先介绍到这里,更多相关文章的可以留意
代码注释