TopcoderArchive
SRM3 Sep 2003
SRM 162

LCMRange

Problem statement, definition, constraints, and public examples.

Problem Statement

The least common multiple of a group of integers is the smallest number that can be evenly divided by all the integers in the group. Given two ints, first and last, find the least common multiple of all the numbers between first and last, inclusive.

Definition

Class:
LCMRange
Method:
lcm
Parameters:
int, int
Returns:
int
Method signature:
int lcm(int first, int last)
(be sure your method is public)

Constraints

  • first will be between 1 and 12, inclusive.
  • last will be between first and 12, inclusive.

Examples

  1. 1
    5
    Returns: 60
    The following statements show how 60 can be divided by all numbers from 1 to 5: 1*60 = 60 2*30 = 60 3*20 = 60 4*15 = 60 5*12 = 60
  2. 4
    5
    Returns: 20
    Although 60 would be a common multiple for 4 and 5, 20 is the least common multiple.
  3. 1
    12
    Returns: 27720
Back to all problems