Given two integers X and Y representing total number of divisors and the number of composite divisors respectively, the task is to check if there exists an integer N which has exactly X divisors and Y are composite numbers.
Input: X = 6, Y = 3
N = 18 is such a number.
The divisors of 18 are 1, 2, 3, 6, 9 and 18.
The composite divisors of 18 are 6, 9 and 18.
Input: X = 7, Y = 3
We see that no such number exists that has 7 positive divisors out of which 3 are composite divisors.
- Firstly calculate the number of prime divisors of a number, which is equal to:
Number of prime divisors = Total number of divisors – Number of composite divisors – 1
- So, number of prime divisors, C = X – Y – 1
- Since every number has 1 as a factor and 1 is neither a prime number nor a composite number, we have to exclude it from being counted in the number of prime divisors.
- If the number of composite divisors is less than the number of prime divisors, then it is not possible to find such a number at all.
- So if the prime factorization of X contains at least C distinct integers, then a solution is possible. Otherwise, we cannot find a number N which will satisfy the given conditions.
- Find the maximum number of values X can be decomposed into such that each value is greater than 1. In other words, we can find out the prime factorization of X.
- If that prime factorization has a number of terms greater than or equal to C, then such a number is possible.
Below is the implementation of the above approach:
Time Complexity: O ( N 1/2)
Auxiliary Space: O (1)
- Check if a number is divisible by all prime divisors of another number
- Check if a number has prime count of divisors
- Check if a number can be expressed as a product of exactly K prime divisors
- Check if there exists a number with X factors out of which exactly K are prime
- Check if a number is Prime, Semi-Prime or Composite for very large numbers
- Check if there exists a prime number which gives Y after being repeatedly subtracted from X
- Find sum of divisors of all the divisors of a natural number
- Find sum of inverse of the divisors when sum of divisors and the number is given
- Check if a number exists having exactly N factors and K prime factors
- Check if count of even divisors of N is equal to count of odd divisors
- Find the maximum number of composite summands of a number
- Find the total number of composite factor for a given number
- Composite Number
- Represent the given number as the sum of two composite numbers
- Count of all subsequence whose product is a Composite number
- Check if count of divisors is even or odd
- Check if sum of divisors of two numbers are same
- Find a sequence of N prime numbers whose sum is a composite number
- C Program to Check if count of divisors is even or odd
- Check if the given array contains all the divisors of some integer
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.