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.


 
#!/bin/ksh
 
# Semiprime - As translated from C
 
#	# Variables:
#
 
#	# Functions:
#
# Function _issemiprime(p2) - return 1 if p2 semiprime, 0 if not
#
function _issemiprime {
	typeset _p2 ; integer _p2=$1
	typeset _p _f ; integer _p _f=0
 
	for ((_p=2; (_f<2 && _p*_p<=_p2); _p++)); do
		while (( _p2 % _p == 0 )); do
			(( _p2 /= _p ))
			(( _f++ ))
		done
	done
 
	return $(( _f + (_p2 > 1) == 2 ))
}
 
 ######
# main #
 ######
 
integer i
for ((i=2; i<100; i++)); do
	_issemiprime ${i}
	(( $? )) && printf " %d" ${i}
done
echo
 