no . of full cycle and remainder
let quo = m / sum ; let rem = m % sum ; let ans = m - quo * sum + 6 ; let x = ( - 1 + Math . pow ( ( 8 * rem ) + 1 , 0.5 ) ) ; ans = ans - x * ( x + 1 ) / 2 ; return parseInt ( ans , 10 ) ; }