Friday, August 26, 2022
HomeWordPress DevelopmentVerify Whether or not a Quantity is an Anti Prime Quantity(Extremely Composite...

Verify Whether or not a Quantity is an Anti Prime Quantity(Extremely Composite Quantity)


View Dialogue

Enhance Article

Save Article

Like Article

View Dialogue

Enhance Article

Save Article

Like Article

Given a constructive integer N, the duty is to inform whether or not it’s an anti-prime quantity or not.

Anti-Prime Numbers (Extremely Composite Quantity):

A constructive integer that has extra divisors than any constructive quantity smaller than it, is named an Anti-Prime Quantity (also referred to as Extremely Composite Quantity).Β 

Following is the listing of the primary 10 anti-prime numbers together with their prime factorizations:

Anti-Prime Quantity Prime Factorization
1 Β 
2 2
4 22
6 2Γ—3
12 22Γ—3
24 23Γ—3
36 22Γ—32
48 24Γ—3
60 22Γ—3Γ—5
120 23Γ—3Γ—5

Examples:

Enter: N = 5040
Output: 5040 is anti-prime
Rationalization: There isn’t any constructive integer lower than 5040 havingΒ 
variety of divisors greater than or equal to the variety of divisors of 5040.

Enter: N = 72
Output: 72 isn’t anti-prime

Strategy:

This query might be solved by counting the variety of divisors of the present quantity after which counting the variety of divisors for every quantity lower than it and checking whether or not any quantity has the variety of divisors larger than or equal to the variety of divisors of N.

Observe the steps to resolve this drawback:

  • Discover what number of components this quantity has.
  • Now iterate until Β N-1 and examine
    • Does any quantity lower than the quantity has components extra or equal to the Β quantityΒ 
    • If sure, then the quantity isn’t an anti-prime quantity.
  • If in the long run not one of the numbers have the variety of divisors larger than or equal to the variety of divisors of N, then N is an anti-prime quantity.

Under is the implementation of the above strategy.

Java

class GFG {

Β Β 

Β Β Β Β 

Β Β Β Β 

Β Β Β Β public static boolean isAntiPrime(int n)

Β Β Β Β {

Β Β Β Β Β Β Β Β int init = Divisors(n);

Β Β Β Β Β Β Β Β for (int i = 1; i < n; i++) {

Β Β Β Β Β Β Β Β Β Β Β Β if (Divisors(i) >= init)

Β Β 

Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β return false;

Β Β Β Β Β Β Β Β }

Β Β Β Β Β Β Β Β return true;

Β Β Β Β }

Β Β 

Β Β Β Β 

Β Β Β Β public static int Divisors(int a)

Β Β Β Β {

Β Β Β Β Β Β Β Β if (a == 1)

Β Β Β Β Β Β Β Β Β Β Β Β return 1;

Β Β 

Β Β Β Β Β Β Β Β 

Β Β Β Β Β Β Β Β int f = 2;

Β Β Β Β Β Β Β Β for (int i = 2; i * i <= a; i++) {

Β Β Β Β Β Β Β Β Β Β Β Β if (a % i == 0) {

Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β if (i * i != a) {

Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β f += 2;

Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β }

Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β else

Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β f++;

Β Β Β Β Β Β Β Β Β Β Β Β }

Β Β Β Β Β Β Β Β }

Β Β Β Β Β Β Β Β return f;

Β Β Β Β }

Β Β 

Β Β Β Β 

Β Β Β Β public static void primary(String args[])

Β Β Β Β {

Β Β Β Β Β Β Β Β int N = 5040;

Β Β 

Β Β Β Β Β Β Β Β 

Β Β Β Β Β Β Β Β if (isAntiPrime(N))

Β Β Β Β Β Β Β Β Β Β Β Β System.out.println(N + " is anti-prime");

Β Β Β Β Β Β Β Β else

Β Β Β Β Β Β Β Β Β Β Β Β System.out.println(N + " isn't anti-prime");

Β Β Β Β }

}

Time Complexity: O(N3/2)
Auxiliary House: O(1)

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments