Max Multiple
Description
Given a divisor
and a bound
, find the largest integer N
such that:
N
is divisible by divisor.N
is less than or equal to bound.N
is greater than 0.
It is guaranteed that such a number exists.
Example
For divisor = 3
and bound = 10
, the output should be
maxMultiple(divisor, bound) = 9
.
The largest integer divisible by 3 and not larger than 10
is 9
.
Input/Output
-
[execution time limit] 4 seconds (js)
-
[input] integer divisor
Guaranteed constraints:
2 \leq divisor \leq 10
. -
[input] integer bound
Guaranteed constraints:
5 \leq bound \leq 100
. -
[output] integer
- The largest integer not greater than
bound
that is divisible bydivisor
.
- The largest integer not greater than
[JavaScript (ES6)] Syntax Tips
1
2
3
4
5
6
// Prints help message to the console
// Returns a string
function helloWorld(name) {
console.log("This prints to the console when you Run Tests");
return "Hello, " + name;
}
Solution
1
2
3
function maxMultiple(divisor, bound) {
return Math.floor(bound / divisor) * divisor;
}