A number is an   attractive number   if the number of its prime factors (whether distinct or not) is also prime.



Example

The number   20,   whose prime decomposition is   2 × 2 × 5,   is an   attractive number   because the number of its prime factors   (3)   is also prime.



Task

Show sequence items up to   120.



Reference

   The OEIS entry:   A063989: Numbers with a prime number of prime divisors.


MAX = 120
 
def is_prime(n)
	d = 5
	if (n < 2)
		return false
	end
	if (n % 2) = 0
		return n = 2
	end
	if (n % 3) = 0
		return n = 3
	end
 
	while (d * d) <= n
		if n % d = 0
			return false
		end
		d += 2
		if n % d = 0
			return false
		end
		d += 4
	end
 
	return true
end
 
def count_prime_factors(n)
	count = 0; f = 2
	if n = 1
		return 0
	end
	if is_prime(n)
		return 1
	end
 
	while true
		if (n % f) = 0
			count += 1
			n /= f
			if n = 1
				return count
			end
			if is_prime(n)
				f = n
			end
		else if f >= 3
			f += 2
		else
			f = 3
		end
	end
end
 
i = 0; n = 0; count = 0
println format("The attractive numbers up to and including %d are:\n", MAX)
for i in range(1, MAX)
	n = count_prime_factors(i)
	if is_prime(n)
		print format("%4d", i)
		count += 1
		if (count % 20) = 0
			println
		end
	end
end
println