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
- Largest number smaller than or equal to n and digits in non-decreasing order
- Largest smaller number possible using only one swap operation
- Find largest number smaller than N with same set of digits
- Largest number divisible by 90 that can be made using 0 and 5
- Largest number with the given set of N digits that is divisible by 2, 3 and 5
- Largest K digit number divisible by X
- C++ Program for Largest K digit number divisible by X
- Largest N digit number divisible by given three numbers
- Sum of largest divisible powers of p (a prime number) in a range
- Java Program for Largest K digit number divisible by X
- Largest Divisor of a Number not divisible by a perfect square
- 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
- Sum of largest prime factor of each number less than equal to n
- Find Largest Special Prime which is less than or equal to a given number
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.