OFFSET
1,1
COMMENTS
LINKS
Gennady Eremin, Table of n, a(n) for n = 1..20000
MAPLE
q:= proc(n) local l, t, i; l:= Bits[Split](n); t:=0;
for i to nops(l) do t:= t-1+2*l[i];
if t<0 then return false fi
od: true
end:
select(isprime and q, [$2..500])[]; # Alois P. Heinz, Jan 07 2022
MATHEMATICA
q[n_] := PrimeQ[n] && AllTrue[Accumulate[(-1)^Reverse[IntegerDigits[n, 2]]], # <= 0 &]; Select[Range[500], q] (* Amiram Eldar, Jan 07 2022 *)
PROG
(Python)
from sympy import isprime
def ok(n):
if n == 0: return True
count = {"0": 0, "1": 0}
for bit in bin(n)[:1:-1]:
count[bit] += 1
if count["0"] > count["1"]: return False
return isprime(n)
print([k for k in range(3, 500, 2) if ok(k)]) # Michael S. Branicky, Jan 07 2022
CROSSREFS
KEYWORD
nonn,base
AUTHOR
Gennady Eremin, Jan 07 2022
STATUS
approved