Is there a way to determine the number of multiples for N unique numbers (provided as an array input) within the range of 1 to K, where 1 < K < 10⁸ and 3 ≤ N < 25?
function findNumberOfMultiples(inputArray, maxSize) {
var count = 0;
var tempArray = [];
for (var i=0; i<maxSize; i++){
tempArray[i] = 0;
}
for (var j=0; j<inputArray.length; j++) {
for (var i=1; i<=maxSize; i++) {
if (i % inputArray[j]) {
tempArray[i-1] = 1;
}
}
}
for (var i=0; i<maxSize; i++) {
if (tempArray[i]==1) {
count++;
}
}
return count;
}
This program may not be efficient when dealing with large values of K. For instance, if you have inputArray = [2,3,4]
and the value of maxSize(k)
is 5
,
- Multiples of 2: 2, 4
- Multiples of 3: 3
- Multiples of 4: 4
Therefore, the total number of multiples of either 2, 3, or 4 in the range of 1 to 5 is 3.