Given a range of integer from ‘a’ to ‘b’ . Our task is to calculate the amount of numbers from the interval [ a, b ], that are not divisible by any number between 2 and k – 1 and yet divisible by k .
Note : We do not have to consider a divisor equal to one.
Input : a = 12, b = 23, k = 3 Output : 2 Between [12, 23], 15 and 21 are the only number which are divisible k and not divisible by any number between 2 and k - 1. Input : a = 1, b = 80, k = 7 Output : 3
Approach : Below is the step by step algorithm to solve this problem:
- A number is divisible only by k and not by any number less than k only if k is a prime number.
- Traverse through each number from a to b to check if the number has the smallest factor as a prime number k.
- Count all such numbers in the range whose smallest factor is a prime number k.
Below is the implementation of the above approach:
- Count all the numbers less than 10^6 whose minimum prime factor is N
- Find kth smallest number in range [1, n] when all the odd numbers are deleted
- Count Odd and Even numbers in a range from L to R
- Count of numbers having only 1 set bit in the range [0, n]
- Count of numbers from range [L, R] whose sum of digits is Y
- Count numbers in range 1 to N which are divisible by X but not by Y
- Count factorial numbers in a given range
- Count the numbers divisible by 'M' in a given range
- Smallest number S such that N is a factor of S factorial or S!
- Count of all even numbers in the range [L, R] whose sum of digits is divisible by 3
- Count numbers from range whose prime factors are only 2 and 3
- Count of common multiples of two numbers in a range
- 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
- Numbers in range [L, R] such that the count of their divisors is both even and prime
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.