php实现水仙花


<?php

class Armstrong {

 static function index(){

  for ( $i = 100; $i < 100000; $i++ ) {

   echo self::is_armstrong($i) ? $i . '<br>' : '';

  }

 }

 static function is_armstrong($num){

  $s = 0;

  $k = strlen($num);

  $d = str_split($num);

  foreach ($d as $r) {

   $s += bcpow($r, $k);

  }

  return $num == $s;

 }

 

}

Armstrong::index();

?>

你可能感兴趣的:(php实现水仙花)