Project Euler Problem 9
Project Euler Problem 9: Find the only Pythagorean triplet, {a, b, c}, for which a + b + c = 1000.
<?php
for ($m = 2 ; ; $m++)
{
for ($n = 1 ; $n < $m; $n++)
{
$a = pow($m, 2)-pow($n, 2);
$b = 2*$m*$n;
$c = pow($m, 2)+pow($n, 2);
if ($a+$b+$c == 1000) break 2;
}
}
echo $a*$b*$c;
?>











0 Comments...
Post a Comment