function fun(min, max, step) { var n = (max - min) / step | 0; return (min + n * step / 2) * ++n; }; alert(fun(9,15,5));