Given an integer N, the task is to check if it can be expressed as a product of exactly K prime divisors.
Input: N = 12, K = 3 Output: Yes Explanation: 12 can be expressed as product of 2×2×3. Input: N = 14, K = 3 Output: No Explanation: 14 can be only expressed as product of 2×7.
To solve the problem mentioned above we are given the value N and we will find the maximum number of values we can split N into. We can represent prime factorization of N as where pi are the prime factors of N and ai are the exponents. We know that total number of divisors of N is . Therefore, we can observe that we have to check whether it is possible to represent N as product of K numbers or not. If the maximum split is less than K then it is not possible to express it in exactly K prime divisors, else it is always possible.
Time Complexity: O(sqrt(N))
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- Check if a prime number can be expressed as sum of two Prime Numbers
- Check whether a number can be expressed as a product of single digit numbers
- Check if a number has prime count of divisors
- Check if a number is divisible by all prime divisors of another number
- Check if N can be expressed as product of 3 distinct numbers
- Check if a number can be expressed as 2^x + 2^y
- Check if a number can be expressed as a^b | Set 2
- Check if a number can be expressed as power | Set 2 (Using Log)
- Sum of all the prime divisors of a number
- Number of divisors of product of N numbers
- Check if a number can be expressed as a sum of consecutive numbers
- Check if a number can be expressed as x^y (x raised to power y)
- Check if a number can be expressed as sum two abundant numbers
- Count of the non-prime divisors of a given number
- Generating all divisors of a number using its prime factorization
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.