3 ms·
So nobody does it? $sum = int($max/2) * ($max+1)); $sum += int(($max+1)/2) if ($max & 1); This is perl of course but it is exploiting the fact that the su
by ChuckMcM 13y ago
So nobody does it?
$sum = int($max/2) * ($max+1));
$sum += int(($max+1)/2) if ($max & 1);
This is perl of course but it is exploiting the fact that the sum of integers is a sum of constants ($max + 1) with an additional term (the 'middle' integer) if the top number is odd.