Given two numbers L and R, the task is to count the number of odd numbers in the range L to R.
Input: l = 3, r = 7
Output: 3 2
Count of odd numbers is 3 i.e. 3, 5, 7
Count of even numbers is 2 i.e. 4, 6
Input: l = 4, r = 8
Approach: Total numbers in the range will be (R – L + 1) i.e. N.
- If N is even then the count of both odd and even numbers will be N/2.
- If N is odd,
- If L or R is odd, then the count of odd number will be N/2 + 1 and even numbers = N – countofOdd.
- Else, count of odd numbers will be N/2 and even numbers = N – countofOdd.
Below is the implementation of the above approach:
Count of odd numbers is 3 Count of even numbers is 2
- Count of numbers having only 1 set bit in the range [0, n]
- Count factorial numbers in a given range
- Count of numbers from range [L, R] whose sum of digits is Y
- Count the numbers divisible by 'M' in a given range
- Count numbers in range 1 to N which are divisible by X but not by Y
- Count numbers in range L-R that are divisible by all of its non-zero digits
- Count numbers with unit digit k in given range
- Count of Numbers in Range where the number does not contain more than K non zero digits
- Count of all even numbers in the range [L, R] whose sum of digits is divisible by 3
- Count all the numbers in a range with smallest factor as K
- Count numbers from range whose prime factors are only 2 and 3
- Sum of numbers in a range [L, R] whose count of divisors is prime
- Count of common multiples of two numbers in a range
- Numbers in range [L, R] such that the count of their divisors is both even and prime
- Count of distinct remainders when N is divided by all the numbers from the range [1, N]
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.