Check if a Number is Sphenic

Given a positive integer n, return true when n is the product of exactly three distinct prime numbers. Otherwise, return false. For example, 30 = 2 × 3 × 5 is…

Given a positive integer `n`, return `true` when `n` is the product of exactly three distinct prime numbers. Otherwise, return `false`. For example, `30 = 2 × 3 × 5` is sphenic. The number `60 = 2 × 2 × 3 × 5` is not because one prime repeats and there are four prime factors with multiplicity.

- `1 ≤ n ≤ 10^6` - `n` is always a positive integer.

Example 1: input n = 30; output true. 30 is the product of the three distinct primes 2, 3, and 5.

Example 2: input n = 42; output true. 42 is 2 × 3 × 7.

Example 3: input n = 60; output false. Its prime factorization contains a repeated 2.

Category: Math. Topic: math. Difficulty: Easy. Patterns: math.