Count of pairs with sum N from first N natural numbers | Funciton to calculate the value of count ; Stores the count of pairs ; Set the two pointers ; Check if the sum of pirs is equal to n ; Increase the count of pairs ; Move to the next pair ; Driver code
def numberOfPairs ( n ) : NEW_LINE INDENT count = 0 NEW_LINE i = 1 NEW_LINE j = n - 1 NEW_LINE while ( i < j ) : NEW_LINE INDENT if ( i + j ) == n : NEW_LINE count += 1 NEW_LINE i += 1 NEW_LINE j -= 1 NEW_LINE DEDENT return count NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT n = 8 NEW_LINE print ( numberOfPairs ( n ) ) NEW_LINE DEDENT