TopCoder problem "MaximalProduct" used in SRM 399 (Division II Level Two)



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

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

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=8760

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=12171&pm=8760

Writer:

andrewzta

Testers:

PabloGilberto , Olexiy , marek.cygan , ivan_metelsky

Problem categories:

Math