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.


include "cowgol.coh";
const MAXIMUM := 120;
 
typedef N is int(0, MAXIMUM + 1);
var prime: uint8[MAXIMUM + 1];
 
sub Sieve() is
    MemSet(&prime[0], 1, @bytesof prime);
    prime[0] := 0;
    prime[1] := 0;
 
    var cand: N := 2;
    while cand <= MAXIMUM >> 1 loop
        if prime[cand] != 0 then
            var comp := cand + cand;
            while comp <= MAXIMUM loop
                prime[comp] := 0;
                comp := comp + cand;
            end loop;
        end if;
        cand := cand + 1;
    end loop;
end sub;
 
sub Factors(n: N): (count: N) is
    count := 0;
    var p: N := 2;
    while p <= MAXIMUM loop
        if prime[p] != 0 then
            while n % p == 0 loop
                count := count + 1;
                n := n / p;
            end loop;
        end if;
        p := p + 1;
    end loop;
end sub;
 
sub Padding(n: N) is
    if n < 10 then print("   ");
    elseif n < 100 then print("  ");
    else print(" ");
    end if;
end sub;
 
var cand: N := 2;
var col: uint8 := 0;
Sieve();
while cand <= MAXIMUM loop
    if prime[Factors(cand)] != 0 then
        Padding(cand);
        print_i32(cand as uint32);
        col := col + 1;
        if col % 18 == 0 then
            print_nl();
        end if;
    end if;
    cand := cand + 1;
end loop;
print_nl();