Find all pairs raised to power K differs by exactly N | Function to prvar pairs 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
function ValidPairs ( X , K ) { var count = 0 ; for ( A = - 1000 ; A <= 1000 ; A ++ ) { for ( B = - 1000 ; B <= 1000 ; B ++ ) { if ( Math . pow ( A , K ) - Math . pow ( B , K ) == X ) { count ++ ; document . write ( A + " " + B + " " ) ; } } } if ( count == 0 ) { document . write ( " " ) ; } } var X = 33 ; var K = 5 ; ValidPairs ( X , K ) ;