MaximalProduct
SRM 399 · 2008-04-24 · by andrewzta
SRM 399 · 2008-04-24 · by andrewzta · Math
Problem Statement
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.
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
0)
10 3 Returns: 36
The 3 positive integers are 3, 3, 4.
1)
10 1 Returns: 10
2)
10 10 Returns: 1
3)
13 8 Returns: 32
4)
7 2 Returns: 12
Submissions are judged against all 148 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Coding Area
Language: C++17 · define a public class MaximalProduct with a public method long long maximalProduct(int s, int k) · 148 test cases · 2 s / 256 MB per case