Given a Natural number N and a whole number L, the task is to find the count of numbers, smaller than or equal to N, such that the difference between the number and sum of its digits is not less than L.
Input: N = 1500, L = 30 Output: 1461 Input: N = 1546300, L = 30651 Output: 1515631
Our solution depends on a simple observation that if a number, say X, is such that the difference of X and sumOfDigits(X) is less than or equal to L, then X+1 is also a valid number. Hence, we have to find a minimum such X using binary search.
Time Complexity: O(log N)
Auxiliary Space: O(1)
- Count Numbers with N digits which consists of odd number of 0's
- Count Numbers with N digits which consists of even number of 0’s
- Count numbers with difference between number and its digit sum greater than specific value
- Count numbers < = N whose difference with the count of primes upto them is > = K
- Count of numbers from range [L, R] whose sum of digits is Y
- Number of digits in the product of two numbers
- Number of digits before the decimal point in the division of two numbers
- Numbers of Length N having digits A and B and whose sum of digits contain only digits A and B
- Program to find count of numbers having odd number of divisors in given range
- Minimum number of digits to be removed so that no two consecutive digits are same
- Print numbers with digits 0 and 1 only such that their sum is N
- Count of alphabets whose ASCII values can be formed with the digits of N
- Minimum sum of two numbers formed from digits of an array in O(n)
- Recursive program to print all numbers less than N which consist of digits 1 or 3 only
- Find the number of positive integers less than or equal to N that have an odd number of digits
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.