zoukankan      html  css  js  c++  java
  • 求质素(素数)

    <?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);
    
    ?>
    
  • 相关阅读:
    系统设计实现
    反编译
    android layout analyze
    2016.7.20-notes
    如何认识刘昊然?
    leetcode-中等-队列-二叉树的层次遍历
    leetcode-简单-栈-逆波兰表达式
    leetcode-简单-栈-有效的括号
    队列-链式队列
    队列-循环队列-顺序存储
  • 原文地址:https://www.cnblogs.com/muyoushui/p/2012793.html
Copyright © 2011-2022 走看看