Project Euler にチャレンジ:Problem 56 PHPでの解答

← Problem 55  Problem 57 →
<?php
$answer = 0;
$pow10 = 10000000000000;
for($a = 1; $a < 100 ; $a++)
{
	for($b = 1; $b < 100 ; $b++)
	{
		$tmp = array(0=>1);
		for($c = 1 ; $c < $b ; $c++)
		{
			$count = count($tmp);
			for($d = 0 ; $d < $count ; $d++)
			{
				$tmp[$d] *= $a;
			}
			for($d = 0 ; $d < $count ; $d++)
			{
				if($tmp[$d] >= $pow10)
				{
					$tmp2 = $tmp[$d] % $pow10;
					@$tmp[$d + 1] += ($tmp[$d] - $tmp2) / $pow10;
					$tmp[$d] = $tmp2;
				}
			}
		}
		$tmp2 = 0;
		foreach($tmp as $v)
		{
			for($i = 0 ; $i < strlen($v);$i++)
			{
				$tmp2 += substr($v,$i,1);
			}
		}
		if($answer < $tmp2)
		{
			$answer = $tmp2;
		}
	}
}

echo $answer."\n";

?>
問題文