Count pairs having distinct sum from a given range | Function to count pairs made up of elements from the range [ L , R ] having distinct sum ; Stores the least sum which can be formed by the pairs ; Stores the highest sum which can be formed by the pairs ; Stores the count of pairs having distinct sum ; Print the count of pairs ; Driver Code ; Function call to count the number of pairs having distinct sum in the range [ L , R ]
def countPairs ( L , R ) : NEW_LINE INDENT firstNum = 2 * L NEW_LINE lastNum = 2 * R NEW_LINE Cntpairs = lastNum - firstNum + 1 NEW_LINE print ( Cntpairs ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT L , R = 2 , 3 NEW_LINE countPairs ( L , R ) NEW_LINE DEDENT