Find unique pairs such that each element is less than or equal to N | Finding the number of unique pairs ; Using the derived formula ; Printing the unique pairs ; Driver Code
def No_Of_Pairs ( N ) : NEW_LINE INDENT i = 1 ; NEW_LINE while ( ( i * i * i ) + ( 2 * i * i ) + i <= N ) : NEW_LINE INDENT i += 1 ; NEW_LINE DEDENT return ( i - 1 ) ; NEW_LINE DEDENT def print_pairs ( pairs ) : NEW_LINE INDENT i = 1 ; NEW_LINE mul = 0 ; NEW_LINE for i in range ( 1 , pairs + 1 ) : NEW_LINE INDENT mul = i * ( i + 1 ) ; NEW_LINE print ( " Pair ▁ no . " , i , " ▁ - - > ▁ ( " , ( mul * i ) , " , ▁ " , mul * ( i + 1 ) , " ) " ) ; NEW_LINE DEDENT DEDENT N = 500 ; NEW_LINE i = 1 ; NEW_LINE pairs = No_Of_Pairs ( N ) ; NEW_LINE print ( " No . ▁ of ▁ pairs ▁ = ▁ " , pairs ) ; NEW_LINE print_pairs ( pairs ) ; NEW_LINE