<?php
$megasum = 0;

for ($i = 3; $i <= 500000; $i++)
{
	$parts = str_split($i);
	$sum = 0;
	
	foreach($parts as $key => $show) {
		$result = 1;
		for ($z = 1; $z <= $show; $z++) {
			$result = $z * $result;
		}
		$sum += $result;
	}
	if ($sum == $i) {
		$megasum += $i;
	}
}
echo $megasum;
?>
Published in: PHP
Download

Related snippets