Given an integer N where 1 ≤ N ≤ 105, the task is to find the number of positive integers less than or equal to N that have an odd number of digits without leading zeros.
Input: N = 11
1, 2, 3, …, 8 and 9 are the numbers ≤ 11
with odd number of digits.
Input: N = 893
Naive approach: Traverse from 1 to N and for each number check if it contains odd digits or not.
Efficient approach: For the values:
- When N < 10 then the count of valid numbers will be N.
- When N / 10 < 10 then 9.
- When N / 100 < 10 then 9 + N – 99.
- When N / 1000 < 10 then 9 + 900.
- When N / 10000 < 10 then 909 + N – 9999.
- Otherwise 90909.
Below is the implementation of the above approach:
- Find the smallest positive number which can not be represented by given digits
- Find the number of integers from 1 to n which contains digits 0's and 1's only
- Find the first N integers such that the sum of their digits is equal to 10
- Find a number x such that sum of x and its digits is equal to given n.
- Find a Number X whose sum with its digits is equal to N
- Count of integers in a range which have even number of odd digits and odd number of even digits
- Number of ways in which N can be represented as the sum of two positive integers
- Maximum number of distinct positive integers that can be used to represent N
- Check whether a number can be represented as sum of K distinct positive integers
- Number of arrays of size N whose elements are positive integers and sum is K
- Count positive integers with 0 as a digit and maximum 'd' digits
- Number of n-digits non-decreasing integers
- Count number of integers less than or equal to N which has exactly 9 divisors
- Find the number of integers x in range (1,N) for which x and x+1 have same number of divisors
- Find the Largest number with given number of digits and sum 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 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.