Thursday, February 04, 2010

Project Euler Problem 6

Project Euler Problem 6: What is the difference between the sum of the squares and the square of the sums?

<?php

function diff_sumsqrs_sqrsums($n)
{
for ($i = $s1 = $s2 = 1; $i < $n;
$i++, $s1 += $i, $s2 += pow($i, 2));
return pow($s1, 2)-$s2;
}

echo diff_sumsqrs_sqrsums(100);

?>

0 Comments...

Post a Comment

 · Blog Index