VOOZH about

URL: https://www.geeksforgeeks.org/dsa/sphenic-number/

⇱ Sphenic Number - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Sphenic Number

Last Updated : 26 Mar, 2024

A Sphenic Number is a positive integer n which is a product of exactly three distinct primes. The first few sphenic numbers are 30, 42, 66, 70, 78, 102, 105, 110, 114, ... 
Given a number n, determine whether it is a Sphenic Number or not. 

Examples: 

Input: 30
Output : Yes
Explanation: 30 is the smallest Sphenic number,
30 = 2 × 3 × 5 the product of the smallest three primes

Input: 60
Output : No
Explanation: 60 = 22 x 3 x 5 has exactly 3 prime factors but is not a sphenic number

Recommended Practice

The sphenic number can be checked by the fact that every sphenic number will have exactly 8 divisors SPHENIC NUMBER
So first We will try to find if the number has exactly 8 divisors if not then the simple answer is no. If there are exactly 8 divisors then we will confirm whether the first 3 digits after 1 are prime or not. 

Eg. 30 (sphenic number) 
30=p*q*r(i.e p,q and r are three distinct prime no and their product are 30) 
the set of divisor is (1,2,3,5,6,10,15,30).

Below is the implementation of the idea. 

Output:

NO

Time Complexity: O(?p log p) 
Auxiliary Space: O(n)

References:
1. OEIS
2. https://en.wikipedia.org/wiki/Sphenic_number

Comment
Article Tags:
Article Tags: