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 ; '' Binary Search ; ' ' ▁ Checks ▁ if ▁ sum ▁ of ▁ first ▁ ' mid ' natural  numbers is greater than equal to X ; '' Update res ; '' Update high ; '' Update low ; ''Driver Code ; '' Input ; '' Finds minimum value of  N such that sum of first  N natural number >= X
def isGreaterEqual ( N , X ) : NEW_LINE INDENT return ( N * ( N + 1 ) // 2 ) >= X ; NEW_LINE DEDENT def minimumPossible ( X ) : NEW_LINE INDENT low = 1 NEW_LINE high = X NEW_LINE res = - 1 ; NEW_LINE while ( low <= high ) : NEW_LINE INDENT mid = low + ( high - low ) // 2 ; NEW_LINE if ( isGreaterEqual ( mid , X ) ) : NEW_LINE INDENT res = mid ; NEW_LINE high = mid - 1 ; NEW_LINE DEDENT else : NEW_LINE INDENT low = mid + 1 ; NEW_LINE DEDENT DEDENT return res NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT X = 14 ; NEW_LINE print ( minimumPossible ( X ) ) ; NEW_LINE DEDENT