Minimum size of Array possible with given sum and product values | Function to find the minimum size of array with sum S and product P ; Base Case ; Iterate through all values of S and check the mentioned condition ; Otherwise , print " - 1" ; Driver Code
def minimumSizeArray ( S , P ) : NEW_LINE INDENT if ( S == P ) : NEW_LINE INDENT return 1 NEW_LINE DEDENT for i in range ( 2 , S + 1 ) : NEW_LINE INDENT d = i NEW_LINE if ( ( S / d ) >= pow ( P , 1.0 / d ) ) : NEW_LINE INDENT return i NEW_LINE DEDENT DEDENT return - 1 NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT S = 5 NEW_LINE P = 6 NEW_LINE print ( minimumSizeArray ( S , P ) ) NEW_LINE DEDENT