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.


 
# syntax: GAWK -f SEMIPRIME.AWK
BEGIN {
    main(0,100)
    main(1675,1680)
    exit(0)
}
function main(lo,hi,  i) {
    printf("%d-%d:",lo,hi)
    for (i=lo; i<=hi; i++) {
      if (is_semiprime(i)) {
        printf(" %d",i)
      }
    }
    printf("\n")
}
function is_semiprime(n,  i,nf) {
    nf = 0
    for (i=2; i<=n; i++) {
      while (n % i == 0) {
        if (nf == 2) {
          return(0)
        }
        nf++
        n /= i
      }
    }
    return(nf == 2)
}
 