TopcoderARCHIVE
Archive/Problems/MaximizingLCM
SRM · Problem 17219

MaximizingLCM

Problem statement, definition, constraints, and public examples.

Problem Statement

Suppose we have to select exactly N positive integers, each between 1 and M, inclusive. (The integers do not have to be distinct.)

Determine and return the largest possible value of the least common multiple of these integers.

Definition

Class:
MaximizingLCM
Method:
maximize
Parameters:
int, long
Returns:
long
Method signature:
long maximize(int N, long M)
(be sure your method is public)

Notes

  • The last constraint implies that the answer for any valid test case won't exceed 10^18.

Constraints

  • N will be between 1 and 50, inclusive.
  • M will be positive.
  • M to the power of N will not exceed 10^18.

Examples

  1. 6
    3
    Returns: 6
    One optimal solution is to select the numbers 1, 1, 1, 2, 2, 3. Their least common multiple is 6, which is clearly the best possible answer.
  2. 10
    10
    Returns: 2520
    Here, the answer is clearly equal to lcm(1,2,3,4,5,6,7,8,9,10).
  3. 3
    47
    Returns: 97290
  4. 4
    62
    Returns: 12718866
← All problems