Semiprime numbers are natural numbers that are products of exactly two (possibly equal) prime numbers.


Semiprimes   are also known as:

   semi-primes
   biprimes
   bi-primes
    2-almost    primes
   or simply:    P2  


Example
 
   1679  =  23 × 73  

(This particular number was chosen as the length of the Arecibo message).



Task

Write a function determining whether a given number is semiprime.



See also

 The Wikipedia article:  semiprime.
 The Wikipedia article:  almost prime.
 The OEIS sequence:  A001358: semiprimes  which has a shorter definition: the product of two primes.


#lang racket
(require math)
 
(define (pair-factorize n)
  "Return all two-number factorizations of a number"
  (let ([up-limit (integer-sqrt n)])
    (map (λ (x) (list x (/ n x)))
	 (filter (λ (x) (<= x up-limit)) (divisors n)))))
 
(define (semiprime n)
  "Determine if a number is semiprime i.e. a product of two primes.
Check if any pair of complete factors consists of primes."
  (for/or ((pair (pair-factorize n)))
    (for/and ((el pair))
      (prime? el))))