function fn(min,max,step){ var n=Math.ceil((max-min)/step); return ((2*min+step*(n-1))/2*n); }; alert(fn(1,7,2)); // 9 ??? 1 + 3 + 5 + 7 = 16