Given two integers X and Y, the task is to find the smallest number greater than or equal to X whose sum of digits is divisible by Y.
Note: 1 <= X <= 1000, 1 <= Y <= 50.
Input: X = 10, Y = 5
14 is the smallest number greater than 10 whose sum of digits (1+4 = 5) is divisible by 5.
Input: X = 5923, Y = 13
Approach: The idea for this problem is to run a loop from X and check for each integer if its sum of digits is divisible by Y or not. Return the first number whose sum of digits is divisible by Y. Given the constraints of X and Y, the answer always exist.
Below is the implementation of the above approach:
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Smallest subarray of size greater than K with sum greater than a given value
- Smallest number greater than or equal to N having sum of digits not exceeding S
- Smallest number greater than Y with sum of digits equal to X
- Smallest number greater than or equal to N divisible by K
- Smallest number greater than or equal to N using only digits 1 to K
- Count numbers in given range such that sum of even digits is greater than sum of odd digits
- Highest and Smallest power of K less than and greater than equal to N respectively
- Count of numbers between range having only non-zero digits whose sum of digits is N and number is divisible by M
- Numbers of Length N having digits A and B and whose sum of digits contain only digits A and B
- Smallest subarray from a given Array with sum greater than or equal to K
- Smallest Special Prime which is greater than or equal to a given number
- Largest number less than N with digit sum greater than the digit sum of N
- Smallest number with given sum of digits and sum of square of digits
- Smallest power of 4 greater than or equal to N
- Size of smallest subarray to be removed to make count of array elements greater and smaller than K equal
- Find smallest number with given number of digits and sum of digits
- Find smallest number with given number of digits and sum of digits under given constraints
- Even digits Sum and Odd digits sum divisible by 4 and 3 respectively
- Smallest number greater than n that can be represented as a sum of distinct power of k
- Kth number exceeding N whose sum of its digits divisible by M
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.