Find all pairs raised to power K differs by exactly N | Function to prpairs whose difference raised to the power K is X ; Stores the count of valid pairs ; Iterate over the range [ - 1000 , 1000 ] ; Iterate over the range [ - 1000 , 1000 ] ; If the current pair satisfies the given condition ; Increment the count by 1 ; If no such pair exists ; Driver Code
def ValidPairs ( X , K ) : NEW_LINE INDENT count = 0 NEW_LINE for A in range ( - 1000 , 1001 , 1 ) : NEW_LINE INDENT for B in range ( - 1000 , 1001 , 1 ) : NEW_LINE INDENT if ( pow ( A , K ) - pow ( B , K ) == X ) : NEW_LINE INDENT count += 1 NEW_LINE print ( A , B ) NEW_LINE DEDENT DEDENT DEDENT if ( count == 0 ) : NEW_LINE INDENT cout << " - 1" NEW_LINE DEDENT DEDENT X = 33 NEW_LINE K = 5 NEW_LINE ValidPairs ( X , K ) NEW_LINE