Wednesday, June 22, 2022
HomeWordPress DevelopmentExamine if given quantity has 7 divisors

Examine if given quantity has 7 divisors


Given a quantity N, the duty is to verify whether or not N has 7 divisors or not.

Examples:

Enter: 64
Output:
Rationalization: 1, 2, 4, 8, 16, 32, 64 -> 7 divisors so output is 1

Enter: 100
Output: 0
Rationalization: 1, 2, 4, 5, 10, 20, 25, 50, 100 -> 8 divisors so output is 0

Enter: 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) = 7

7 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++

  

#embrace <bits/stdc++.h>

utilizing namespace std;

  

int sevenDivisors(int N)

{

    

    int ok = pow(N, 1 / 6.);

  

    

    

    int res = pow(ok, 6);

  

    

    

    if (N == res)

        return 1;

    return 0;

}

  

int important()

{

    int N = 64;

  

    

    bool ans = sevenDivisors(N);

    if (ans)

        cout << "Sure";

    else

        cout << "No";

    return 0;

}

Time Complexity: O(logN)
Auxiliary Area: O(1)

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments