Check if a Number is Semiprime
Given a positive integer n, return true when n is the product of exactly two prime numbers. Otherwise, return false. Count prime factors with multiplicity, so…
Given a positive integer `n`, return `true` when `n` is the product of exactly two prime numbers. Otherwise, return `false`. Count prime factors with multiplicity, so `4 = 2 × 2` and `15 = 3 × 5` are both semiprime, while `8 = 2 × 2 × 2` is not.
- `1 ≤ n ≤ 10^6` - `n` is always a positive integer.
Example 1: input n = 15; output true. 15 is the product of the two primes 3 and 5.
Example 2: input n = 49; output true. 49 is 7 × 7; repeated prime factors still count separately.
Example 3: input n = 8; output false. 8 has three prime factors with multiplicity.
Category: Math. Topic: math. Difficulty: Easy. Patterns: math.