Given two numbers N and K, the task is to find whether an integer X exists such that it has exactly N factors and K out of them are prime.
Input: N = 4, K = 2
One possible number for X is 6.
The number 6 has a total 4 factors: 1, 2, 3 & 6.
It also has exactly 2 prime factors: 2 & 3.
Input: N = 3, K = 1
One possible number for X is 49.
The number 49 has a total 3 factors: 1, 7, & 49.
It also has exactly 1 prime factor: 7.
Approach: The idea is to use the following identity.
- For any number X, if the number has N factors out of which K are prime:
X = k1a + k2b + k3c + ... + knn
- The total number of factors N is equal to:
N = (a + 1) * (b + 1) * (c + 1) .. (n + 1)
- Therefore, the idea is to check if N can be represented as a product of K integers greater than 1. This can be done by finding the divisors of the number N.
- If the count of this is less than K, then the answer is not possible. Else, it is possible.
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.
- Check if there exists a number with X factors out of which exactly K are prime
- Check if all Prime factors of number N are unique or not
- Print all numbers whose set of prime factors is a subset of the set of the prime factors of X
- Maximum number of prime factors a number can have with exactly x factors
- Find number of factors of N when location of its two factors whose product is N is given
- Prime factors of a big number
- Sum of Factors of a Number using Prime Factorization
- Number of steps to convert to prime factors
- Product of unique prime factors of a number
- Maximum number of unique prime factors
- Generate K co-prime pairs of factors of a given number
- C Program for efficiently print all prime factors of a given number
- Efficient program to print all prime factors of a given number
- Number less than equals to N with maximum product of prime factors
- Number of distinct prime factors of first n natural numbers
- Product of divisors of a number from a given list of its prime factors
- Java Program for efficiently print all prime factors of a given number
- Number which has the maximum number of distinct prime factors in the range M to N
- Super Ugly Number (Number whose prime factors are in given set)
- Check whether a number has exactly three distinct factors or not
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.