SRM431 DIV2 1000

A list of non-negative numbers is called satisfactory if the sum of the numbers in the list is equal to S and the product of the numbers is equal to P. Find a satisfactory list with the least possible number of elements, and return its size. If no such list exists, return -1 instead. Please note that the list may contain non-integer numbers.

解けませんでした。。。

以下が答え
合計S,積Pを満たす要素の数(最小の)を返す

for(int i=2;i<=S+1;i++){
a = pow((double)P, 1.0/(double)i); // P^(1/i) 
b = (double)S/(double)i; // S/i
}

a<=bを満たすときのiを返せばよい。