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.


MODULE AttractiveNumbers;
FROM InOut IMPORT WriteCard, WriteLn;
 
CONST
    Max = 120;
 
VAR
    n, col: CARDINAL;
    Prime: ARRAY [1..Max] OF BOOLEAN;
 
PROCEDURE Sieve;
VAR i, j: CARDINAL;
BEGIN
    Prime[1] := FALSE;
    FOR i := 2 TO Max DO
        Prime[i] := TRUE;
    END;
 
    FOR i := 2 TO Max DIV 2 DO
        IF Prime[i] THEN
            j := i*2;
            WHILE j <= Max DO
                Prime[j] := FALSE;
                j := j + i;
            END;
        END;
    END;
END Sieve;
 
PROCEDURE Factors(n: CARDINAL): CARDINAL;
VAR i, factors: CARDINAL;
BEGIN
    factors := 0;
    FOR i := 2 TO Max DO
        IF i > n THEN
            RETURN factors;
        END;
        IF Prime[i] THEN
            WHILE n MOD i = 0 DO
                n := n DIV i;
                factors := factors + 1;
            END;
        END;
     END;
     RETURN factors;
END Factors;
 
BEGIN
    Sieve();
    col := 0;
    FOR n := 2 TO Max DO
        IF Prime[Factors(n)] THEN
            WriteCard(n, 4);
            col := col + 1;
            IF col MOD 15 = 0 THEN
                WriteLn();
            END;
        END;
    END;
    WriteLn();
END AttractiveNumbers.