算法,水仙花数 EQPHP ?phpclass a_test{private $static_class;static function index(){//for ( $i = 100; $i 1000000; $i++ ) { for ( $i = 100; $i 1000; ++$i ) {if (self::is_narcissus($i) )echo 'Narcissus: '.$i.'br';}}static function cube($num){
算法,水仙花数 EQPHP
<?php class a_test{ private $static_class; static function index(){ //for ( $i = 100; $i < 1000000; $i++ ) { for ( $i = 100; $i < 1000; ++$i ) { if (self::is_narcissus($i) ) echo 'Narcissus: '.$i.'<br>'; } } static function cube($num){ return $num * $num * $num; } static function is_narcissus($num){ $hundreds = floor($num / 100); //分解出百位 $tens = floor($num / 10 ) % 10; //分解出十位 $ones = floor($num % 10 ); //分解出个位 return (bool)(self::cube($hundreds)+self::cube($tens)+self::cube($ones) == $num); } }