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:
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Count all the numbers less than 10^6 whose minimum prime factor is N
- Smallest number S such that N is a factor of S factorial or S!
- Numbers with sum of digits equal to the sum of digits of its all prime factor
- Queries on the sum of prime factor counts in a range
- Most frequent factor in a range of integers
- Find kth smallest number in range [1, n] when all the odd numbers are deleted
- Number of ways to obtain each numbers in range [1, b+c] by adding any two numbers in range [a, b] and [b, c]
- Exactly n distinct prime factor numbers from a to b
- Print the kth common factor of two numbers
- Least prime factor of numbers till n
- Program to find HCF (Highest Common Factor) of 2 Numbers
- Count of pairs (i, j) in the array such that arr[i] is a factor of arr[j]
- Count of distinct power of prime factor of N
- Count minimum factor jumps required to reach the end of an Array
- Sum of all prime divisors of all the numbers in range L-R
- Count numbers in range L-R that are divisible by all of its non-zero digits
- Count of all even numbers in the range [L, R] whose sum of digits is divisible by 3
- Count of distinct remainders when N is divided by all the numbers from the range [1, N]
- Count of numbers with all digits same in a given range
- Count all prime numbers in a given range whose sum of digits is also 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 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.