Check if a number can be represented as product of two positive perfect cubes | Function to check if N can be represented as the product of two perfect cubes or not ; Stores the perfect cubes ; Traverse the Map ; Stores the first number ; Stores the second number ; Search the pair for the first number to obtain product N from the Map ; If N cannot be represented as the product of the two positive perfect cubes ; Driver Code
def productOfTwoPerfectCubes ( N ) : NEW_LINE INDENT cubes = { } NEW_LINE i = 1 NEW_LINE while i * i * i <= N : NEW_LINE INDENT cubes [ i * i * i ] = i NEW_LINE i += 1 NEW_LINE DEDENT for itr in cubes : NEW_LINE INDENT firstNumber = itr NEW_LINE if ( N % itr == 0 ) : NEW_LINE INDENT secondNumber = N // itr NEW_LINE if ( secondNumber in cubes ) : NEW_LINE INDENT print ( " Yes " ) NEW_LINE return NEW_LINE DEDENT DEDENT DEDENT print ( " No " ) NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT N = 216 NEW_LINE productOfTwoPerfectCubes ( N ) NEW_LINE DEDENT