A   pernicious number   is a positive integer whose   population count   is a prime.

The   population count   is the number of   ones   in the binary representation of a non-negative integer.



Example
22   (which is   10110   in binary)   has a population count of   3,   which is prime,   and therefore

22   is a pernicious number.



Task
 display the first   25   pernicious numbers   (in decimal).
 display all pernicious numbers between   888,888,877   and   888,888,888   (inclusive).
 display each list of integers on one line   (which may or may not include a title).


See also
 Sequence   A052294 pernicious numbers on The On-Line Encyclopedia of Integer Sequences.
 Rosetta Code entry   population count, evil numbers, odious numbers.


MODULE Pernicious;
FROM FormatString IMPORT FormatString;
FROM Terminal IMPORT WriteString,WriteLn,ReadChar;
 
PROCEDURE IsPrime(x : LONGINT) : BOOLEAN;
VAR i : LONGINT;
BEGIN
    IF x<2 THEN RETURN FALSE END;
    FOR i:=2 TO x-1 DO
        IF x MOD i = 0 THEN RETURN FALSE END
    END;
    RETURN TRUE
END IsPrime;
 
PROCEDURE BitCount(x : LONGINT) : LONGINT;
VAR count : LONGINT;
BEGIN
    count := 0;
    WHILE x>0 DO
        x := x BAND (x-1);
        INC(count)
    END;
    RETURN count
END BitCount;
 
VAR
    buf : ARRAY[0..63] OF CHAR;
    i,n : LONGINT;
BEGIN
    i := 1;
    n := 0;
    WHILE n<25 DO
        IF IsPrime(BitCount(i)) THEN
            FormatString("%l ", buf, i);
            WriteString(buf);
            INC(n)
        END;
        INC(i)
    END;
    WriteLn;
 
    FOR i:=888888877 TO 888888888 DO
        IF IsPrime(BitCount(i)) THEN
            FormatString("%l ", buf, i);
            WriteString(buf)
        END;
    END;
 
    ReadChar
END Pernicious.