Given a number N and a number K, the task is to find the largest number smaller than or equal to N which is divisible by K.
Input: N = 45, K = 6 Output: 42 42 is the largest number smaller than or equal to 45 which is divisible by 6. Input: N = 11, K = 3 Output: 9
Approach: The idea is to divide the N by K. If the remainder is 0 then print N else print N – remainder.
Below is the implementation of the above approach:
Largest number smaller than or equal to 45 that is divisible by 6 is 42
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- Largest number smaller than or equal to n and digits in non-decreasing order
- Find the largest number smaller than integer N with maximum number of set bits
- Largest smaller number possible using only one swap operation
- Find largest number smaller than N with same set of digits
- Maximize number of groups formed with size not smaller than its largest element
- Largest number divisible by 90 that can be made using 0 and 5
- Largest K digit number divisible by X
- Largest number with the given set of N digits that is divisible by 2, 3 and 5
- C++ Program for Largest K digit number divisible by X
- Largest N digit number divisible by given three numbers
- Largest Divisor of a Number not divisible by a perfect square
- Java Program for Largest K digit number divisible by X
- Sum of largest divisible powers of p (a prime number) in a range
- Smallest number greater than or equal to N divisible by K
- Largest number less than or equal to N/2 which is coprime to N
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.