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