Find the smallest value of N such that sum of first N natural numbers is â ‰¥ X | Function to check if sum of first N natural numbers is >= X ; Finds minimum value of N such that sum of first N natural number >= X ; Check if sum of first i natural number >= X ; Input ; Finds minimum value of N such that sum of first N natural number >= X
function isGreaterEqual ( N , X ) { return parseInt ( ( N * ( N + 1 ) ) / 2 ) >= X ; } function minimumPossible ( X ) { for ( let i = 1 ; i <= X ; i ++ ) { if ( isGreaterEqual ( i , X ) ) return i ; } } let X = 14 ; document . write ( minimumPossible ( X ) ) ;