TopcoderArchiveVisit Topcoder
SRM24 Apr 2008
SRM 399

MaximalProduct

Problem statement, definition, constraints, and public examples.

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

  1. 10
    3
    Returns: 36
    The 3 positive integers are 3, 3, 4.
  2. 10
    1
    Returns: 10
  3. 10
    10
    Returns: 1
  4. 13
    8
    Returns: 32
  5. 7
    2
    Returns: 12
Back to all problems