Connection Status:
Competition Arena > LCMRange
SRM 162 · 2003-09-03 · by schveiguy · Brute Force, Math
Class Name: LCMRange
Return Type: int
Method Name: lcm
Arg Types: (int, int)
Problem Statement

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.

Constraints

  • first will be between 1 and 12, inclusive.
  • last will be between first and 12, inclusive.
Examples
0)
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

1)
4
5
Returns: 20

Although 60 would be a common multiple for 4 and 5, 20 is the least common multiple.

2)
8
12
Returns: 3960
3)
1
12
Returns: 27720
4)
1
6
Returns: 60

Submissions are judged against all 61 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class LCMRange with a public method int lcm(int first, int last) · 61 test cases · 2 s / 256 MB per case

Submitting as anonymous