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.


% The population count of an integer is never going to be
% higher than the amount of bits in it (max 64)
% so we can get away with a very simple primality test.
is_prime = proc (n: int) returns (bool)
    if n<=2 then return(n=2) end
    if n//2=0 then return(false) end
    for i: int in int$from_to_by(n+2, n/2, 2) do
        if n//i=0 then return(false) end
    end
    return(true)
end is_prime
 
% Find the population count of a number
pop_count = proc (n: int) returns (int)
    c: int := 0
    while n > 0 do
        c := c + n // 2
        n := n / 2
    end
    return(c)
end pop_count
 
% Is N pernicious?
pernicious = proc (n: int) returns (bool)
    return(is_prime(pop_count(n)))
end pernicious
 
start_up = proc () 
    po: stream := stream$primary_output()
 
    stream$putl(po, "First 25 pernicious numbers: ")
    n: int := 1
    seen: int := 0
    while seen<25 do
        if pernicious(n) then
            stream$puts(po, int$unparse(n) || " ")
            seen := seen + 1
        end
        n := n + 1
    end
 
    stream$putl(po, "\nPernicious numbers between 888,888,877 and 888,888,888:")
    for i: int in int$from_to(888888877,888888888) do
        if pernicious(i) then
            stream$puts(po, int$unparse(i) || " ")
        end
    end
end start_up