Given a quantity N, the duty is to verify whether or not N has 7 divisors or not.
Examples:
Enter: 64
Output: 1
Rationalization: 1, 2, 4, 8, 16, 32, 64 -> 7 divisors so output is 1Enter: 100
Output: 0
Rationalization: 1, 2, 4, 5, 10, 20, 25, 50, 100 -> 8 divisors so output is 0Enter: 729
Output: 1
Rationalization: 1, 2, 4, 8, 16, 32, 64 -> 7 divisors so output is 1
Method: The issue could be solved primarily based on the next mathematical statement:
The prime factorization of a quantity is:
N = p1e1 * p2e2 * . . . * pnen
So variety of divisors = ( e1 + 1 ) * (e2 + 1) *. . . * (en + 1).On this case, variety of divisors = 7 .
So, ( e1 + 1 ) * (e2 + 1) *. . . * (en + 1) = 77 is multiplication of at most 2 pure numbers.
So, it may be solely written as ( e1 + 1 ) * (e2 + 1) = 1 * 7
So, e1 = 0 & e2 = 6 from above equation.
So, it’s clear that for 7 divisors just one case is feasible and that’s (prime quantity)6. Observe the steps to unravel the issue:
- Examine if N(1/6) is a prime quantity or not.
- Whether it is prime quantity then output “Sure”.
- In any other case, the output can be “No”.
Under is the implementation of the above strategy:
C++
|
Time Complexity: O(logN)
Auxiliary Area: O(1)