Connection Status:
Competition Arena > CommonMultiples
SRM 346 · 2007-04-24 · by soul-net · Simple Math
Class Name: CommonMultiples
Return Type: int
Method Name: countCommMult
Arg Types: (vector<int>, int, int)
Problem Statement

Problem Statement

You will be given a int[] a and two ints lower and upper. Return the number of integers between lower and upper, inclusive, that are multiples of all members of a.

Constraints

  • a will contain between 1 and 50 elements, inclusive.
  • Each element of a will be between 1 and 100, inclusive.
  • upper will be between 1 and 2000000000 (2*109), inclusive.
  • lower will be between 1 and upper, inclusive.
Examples
0)
{1,2,3}
5
15
Returns: 2

The only numbers between 5 and 15 that are multiples of 1, 2 and 3 are 6 and 12.

1)
{1,2,4,8,16,32,64}
128
128
Returns: 1

128 is a multiple of all smaller powers of 2.

2)
{2,3,5,7,11,13,17,19,23,29,31,37,41,43,49}
1
2000000000
Returns: 0
3)
{1,1,1}
1
2000000000
Returns: 2000000000
4)
{4}
1
2000000000
Returns: 500000000

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

Coding Area

Language: C++17 · define a public class CommonMultiples with a public method int countCommMult(vector<int> a, int lower, int upper) · 192 test cases · 2 s / 256 MB per case

Submitting as anonymous