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
- Maximum number of prime factors a number can have with exactly x factors
- First element of every K sets having consecutive elements with exactly K prime factors less than N
- Print all numbers whose set of prime factors is a subset of the set of the prime factors of X
- Check whether a number has exactly three distinct factors or not
- Maximum possible prime divisors that can exist in numbers having exactly N divisors
- Count of subarrays having exactly K prime numbers
- Count numbers in a range having GCD of powers of prime factors equal to 1
- Check if a number can be expressed as a product of exactly K prime divisors
- Check if there exists a prime number which gives Y after being repeatedly subtracted from X
- Number of factors of very large number N modulo M where M is any prime number
- Queries to find whether a number has exactly four distinct factors or not
- Check if all Prime factors of number N are unique or not
- Check if each element of the given array is the product of exactly K prime numbers
- Find number of factors of N when location of its two factors whose product is N is given
- Super Ugly Number (Number whose prime factors are in given set)
- Number with maximum number of prime factors
- Number which has the maximum number of distinct prime factors in the range M to N
- Check if a prime number can be expressed as sum of two Prime Numbers
- Find an array of size N having exactly K subarrays with sum S
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.