Sum and Product
Time limit2sMemory limit128 MB
Given a sum S and a product P, find the smallest list of nonnegative reals whose sum is S and product is P, or report -1 if impossible.
- Level
Medium6 of 10
- Topics
- Math, Binary search
- Solved
- No attempts yet
Problem
Consider a list of nonnegative numbers. If the sum of all numbers in the list is S and their product is P, call the list valid.
Given S and P, find the minimum possible size of a valid list. The size of a list is the number of numbers it contains. If no such list exists, print -1.
The numbers in the list are not required to be integers.
Input
The first line contains two natural numbers S and P, separated by a space. Each number is at most 1,000,000,000.
Output
Print the answer on the first line.