Check if a number can be represented as sum of two positive perfect cubes | Function to check if N can be represented as sum of two perfect cubes or not ; Stores the perfect cubes of first N natural numbers ; Traverse the map ; Stores first number ; Stores second number ; Search the pair for the first number to obtain sum N from the Map ; If N cannot be represented as sum of two positive perfect cubes ; Function call to check if N can be represented as sum of two perfect cubes or not
def sumOfTwoPerfectCubes ( 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 secondNumber = N - itr NEW_LINE if secondNumber in cubes : NEW_LINE INDENT print ( " True " , end = " " ) NEW_LINE return NEW_LINE DEDENT DEDENT print ( " False " , end = " " ) NEW_LINE DEDENT N = 28 NEW_LINE sumOfTwoPerfectCubes ( N ) NEW_LINE