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.


 
Const limite = 120
 
Declare Function esPrimo(n As Integer) As Boolean
Declare Function ContandoFactoresPrimos(n As Integer) As Integer
 
Function esPrimo(n As Integer) As Boolean
    If n < 2 Then Return false
    If n Mod 2 = 0 Then Return n = 2
    If n Mod 3 = 0 Then Return n = 3
    Dim As Integer d = 5
    While d * d <= n
        If n Mod d = 0 Then Return false
        d += 2
        If n Mod d = 0 Then Return false
        d += 4
    Wend
    Return true
End Function
 
Function ContandoFactoresPrimos(n As Integer) As Integer
    If n = 1 Then Return false
    If esPrimo(n) Then Return true
    Dim As Integer f = 2, contar = 0
    While true
        If n Mod f = 0 Then
            contar += 1
            n = n / f
            If n = 1 Then Return contar
            If esPrimo(n) Then f = n
        Elseif f >= 3 Then
            f += 2
        Else 
            f = 3
        End If
    Wend
End Function
 
' Mostrar la sucencia de números atractivos hasta 120.
Dim As Integer i = 1, longlinea = 0
 
Print "Los numeros atractivos hasta e incluyendo"; limite; " son: "
While i <= limite
    Dim As Integer n = ContandoFactoresPrimos(i)
    If esPrimo(n) Then
        Print Using "####"; i;
        longlinea += 1: If longlinea Mod 20 = 0 Then Print ""
    End If
    i += 1
Wend
End
 