Given a number N. The task is to find the number of integers from 1 to n which contains digits 0’s and 1’s only.
Input : N = 15 Output : 3 Explanation : 1, 10, 11 are such integers. Input : N = 120 Output : 7 Explanation : 1, 10, 11, 100, 101, 110, 111 are such integers.
Approach: An efficient approach is to build integers which contain 1’s and 0’s only using a recursive function starting from the number 1. For each number check whether it is less than n or not.
Below is the implementation of the above approach:
- Find the number of positive integers less than or equal to N that have an odd number of digits
- Count of integers in a range which have even number of odd digits and odd number of even digits
- Find the first N integers such that the sum of their digits is equal to 10
- Find the average of k digits from the beginning and l digits from the end of the given number
- Find the Largest number with given number of digits and sum of digits
- Find the number of integers x in range (1,N) for which x and x+1 have same number of divisors
- Find integers that divides maximum number of elements of the array
- Find count of digits in a number that divide the number
- Find maximum number that can be formed using digits of a given number
- Find the smallest number whose digits multiply to a given number n
- Find first and last digits of a number
- Given a number n, find the first k digits of n^n
- Find M-th number whose repeated sum of digits of a number is N
- Find the n-th number made of even digits only
- Find next greater number with same set 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.