/ Published in: PHP
URL: http://reusablecode.blogspot.com/2009/01/perfect-numbers.html
Determine whether the given number is a perfect number.
Expand |
Embed | Plain Text
<?php /* Copyright (c) 2009, reusablecode.blogspot.com; some rights reserved. This work is licensed under the Creative Commons Attribution License. To view a copy of this license, visit http://creativecommons.org/licenses/by/3.0/ or send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA. */ // Determine whether the given number is a perfect number. function isPerfect($number) { // Only positive integers can be perfect. if ($number < 1) { return false; } // Calculate the factors for the given number. for($i = 1; $i <= $number; $i++) { if ($number % $i == 0) { $arrFactors[] = $i; } } // A perfect number is a number that is half the sum of all of its positive divisors (including itself). } ?>
You need to login to post a comment.
