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
function minimumSizeArray ( S , P ) { if ( S == P ) { return 1 ; } for ( let i = 2 ; i <= S ; i ++ ) { let d = i ; if ( ( S / d ) >= Math . pow ( P , 1.0 / d ) ) { return i ; } } return - 1 ; } let S = 5 , P = 6 ; document . write ( minimumSizeArray ( S , P ) ) ;