Created
September 21, 2015 14:43
-
-
Save imiskolee/93c066738839ad4258a2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/*** | |
* =================================================================== * | |
* -------------------- About Perfect Num Analytize ------------------ * | |
* =================================================================== * | |
* Author : Misko_Lee(imiskolee#at#gmail.com) | |
* Create At : 2015-09-21 22:17 | |
***/ | |
$cache_list = array(); | |
for($m=0;$m<2;$m++){ | |
echo "\n\n"; | |
$start_time = microtime(true); | |
$perfect_count = 0; | |
$abundant_count = 0; | |
$deficient_count = 0; | |
$end_num = $argv[1]; | |
for($i=1;$i<$end_num;$i++){ | |
if(isset($cache_list[$i])){ | |
$aliquot_sum = $cache_list[$i]; | |
}else{ | |
$aliquot_sum = 0; | |
for($j=1;$j<$i;$j++){ | |
if($i % $j == 0){ | |
$aliquot_sum += $j; | |
} | |
} | |
$cache_list[$i] = $aliquot_sum; | |
} | |
if($aliquot_sum == $i){ | |
$perfect_count++; | |
}else if($aliquot_sum > $i){ | |
$abundant_count++; | |
}else{ | |
$deficient_count++; | |
} | |
} | |
$end_time = microtime(true); | |
echo "\n"; | |
echo "Ranage at 1 ..".$end_num."\n"; | |
echo "Perfect Num Count:".$perfect_count."\n"; | |
echo "Abundant Num Count:".$abundant_count."\n"; | |
echo "Deficient Num Count:".$deficient_count."\n"; | |
echo "Real Complete Time:".(($end_time - $start_time) * 1000) .'ms'."\n"; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment