text: Find Cube Pairs | Set 1 ( A n ^ ( 2 / 3 ) Solution ) | Function to find pairs that can represent the given number as sum of two cubes ; Find cube root of n ; Create an empty map ; Consider all pairs such with values less than cuberoot ; Find sum of current pair ( x , y ) ; Do nothing if sum is not equal to given number ; If sum is seen before , we found two pairs ; If sum is seen for the first time ; Driver code
code: def findPairs ( n ) : NEW_LINE INDENT cubeRoot = pow ( n , 1.0 / 3.0 ) ; NEW_LINE s = { } NEW_LINE for x in range ( int ( cubeRoot ) ) : NEW_LINE INDENT for y in range ( x + 1 , int ( cubeRoot ) + 1 ) : NEW_LINE INDENT sum = x * x * x + y * y * y ; NEW_LINE if ( sum != n ) : NEW_LINE INDENT continue ; NEW_LINE DEDENT if sum in s . keys ( ) : NEW_LINE INDENT print ( " ( " + str ( s [ sum ] [ 0 ] ) + " , ▁ " + str ( s [ sum ] [ 1 ] ) + " ) ▁ and ▁ ( " + str ( x ) + " , ▁ " + str ( y ) + " ) " +   " " ) NEW_LINE DEDENT else : NEW_LINE INDENT s [ sum ] = [ x , y ] NEW_LINE DEDENT DEDENT DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT n = 13832 NEW_LINE findPairs ( n ) NEW_LINE DEDENT