Problem Statement
You are given an integer s and an integer k. Find k positive integers a1, a2, ..., ak such that their sum is equal to s and their product is the maximal possible. Return their product.
Definition
- Class:
- MaximalProduct
- Method:
- maximalProduct
- Parameters:
- int, int
- Returns:
- long
- Method signature:
- long maximalProduct(int s, int k)
- (be sure your method is public)
Notes
- For all valid inputs, the return value will fit in a long.
Constraints
- k will be between 1 and 20, inclusive.
- s will be between k and 100, inclusive.
Examples
10
3
Returns: 36
The 3 positive integers are 3, 3, 4.10
1
Returns: 10
10
10
Returns: 1
13
8
Returns: 32
7
2
Returns: 12