


The first line contains an integer ‘Q’ denoting the number of queries.
The next ‘Q’ lines contain three space-separated integers ‘A’, ‘B’ and ‘N’ which are described in the problem statement.
For each query, print the number of integers in the range [A, B] which has exactly ‘N’ unique prime factors.
The output of each query will be printed in a separate line.
You are not required to print the expected output, it has already been taken care of. Just implement the function.
1 <= Q <= 10000
1 <= A, B <= 10000
1 <= N <= 10
Where ‘Q’ is the number of queries and ‘A’, 'B’ and ‘N’ are three integers as described in the problem statement.
Time limit: 1 sec
The basic idea of this approach is to iterate through each integer in the given range for each query and check the number of unique prime factors.
Let us try to implement a function primeFactors(int n) which returns the number of unique prime factors for a given integer.
Algorithm:
Now consider the following steps for finding the answer for each query.
Since for each query, 1 <= N <= 10 we can store the integers in the range [1, 100000] which are having unique prime factors less than or equal to 10.
Algorithm:
Now, for answering the query we will iterate through the list of integers having ‘n’ number unique prime factors and count the integers in the range [A, B].
Let us try to optimize the primeFactors() function. The basic idea is to store the Smallest Prime Factor(SPF) for every number in the range [1, 10000]. And then to calculate the prime factorization of the given number by dividing the given number recursively with its smallest prime factor till it becomes 1.
Algorithm:
Now let us implement the primeFactors(int n) function:
Since for each query, 1 <= N <= 10 we can store the integers in the range [1, 10000] which are having unique prime factors less than or equal to 10.
Algorithm:
Since each array/list of “bin” is sorted in non-decreasing order, for answering the query we can do a binary search to find the number of integers in the range [A, B] from the list of integers having ‘n’ number of unique prime factors.
Pair Product Div by K
Pair Product Div by K
Merge Two Sorted Arrays Without Extra Space
Merge Two Sorted Arrays Without Extra Space
Co-Prime
First Digit One
Special Digit Numbers