Find all pairs raised to power K differs by exactly N | C ++ program for the above approach ; Function to print 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
#include <bits/stdc++.h> NEW_LINE using namespace std ; void ValidPairs ( int X , int K ) { long long int count = 0 ; for ( int A = -1000 ; A <= 1000 ; A ++ ) { for ( int B = -1000 ; B <= 1000 ; B ++ ) { if ( pow ( A , K ) - pow ( B , K ) == X ) { count ++ ; cout << A << " ▁ " << B << endl ; } } } if ( count == 0 ) { cout << " - 1" ; } } int main ( ) { long long int X = 33 ; int K = 5 ; ValidPairs ( X , K ) ; return 0 ; }