Find n | Returns n - th number in sequence 1 , 1 , 2 , 1 , 2 , 3 , 1 , 2 , 4 , ... ; One by one subtract counts elements in different blocks ; Driver code
function findNumber ( n ) { n -- ; let i = 1 ; while ( n >= 0 ) { n -= i ; ++ i ; } return ( n + i ) ; } let n = 3 ; document . write ( findNumber ( n ) ) ;