login
A145576
a(n) is the smallest prime with both exactly an n number of 0's and exactly an n number of 1's in its binary representation. a(n) = 0 if no such prime exists.
1
2, 0, 37, 139, 541, 2141, 8287, 33119, 131519, 525247, 2098687, 8391679, 33561599, 134242271, 536895487, 2147548159, 8590061567, 34360196863, 137439412223, 549756861439, 2199026663423, 8796097216447, 35184380411903
OFFSET
1,1
LINKS
EXAMPLE
a(3) = 37 = 100101 (base 2) is the smallest prime with three 0's and three 1's in its binary representation. - R. J. Mathar, Oct 14 2008
MAPLE
A000120 := proc(n) local d; add(d, d=convert(n, base, 2)) ; end: A080791 := proc(n) local d, dgs; dgs := convert(n, base, 2) ; nops(dgs)-add(d, d=dgs) ; end: A070939 := proc(n) max(1, ilog2(n)+1) ; end: A145576 := proc(n) local p, pbin; p := nextprime(2^(2*n-1)-1); while true do pbin := A070939(p) ; if pbin > 2*n then RETURN(0) ; elif pbin = 2*n then if A000120(p) = n and A080791(p) = n then RETURN(p) ; fi; fi; p := nextprime(p) ; od: end: seq(A145576(n), n=1..30) ; # R. J. Mathar, Oct 14 2008
# Alternative:
F:= proc(n) local c, x;
c:= [$n+1..2*n-2];
do
x:= 2^(2*n-1)+1+add(2^(2*n-1-c[i]), i=1..n-2);
if isprime(x) then return x fi;
c:= combinat:-prevcomb(c, 2*n-2)
od
end proc:
2, 0, seq(F(n), n=3..30); # Robert Israel, Sep 24 2017
MATHEMATICA
Table[SelectFirst[Prime@ Apply[Range, PrimePi@{2^(2 (n - 1)) + 1, 2^(2 n) - 1}], Union@ DigitCount[#, 2] == {n} &] /. k_ /; MissingQ@ k -> 0, {n, 12}] (* Michael De Vlieger, Sep 24 2017 *)
CROSSREFS
Sequence in context: A347900 A337817 A120489 * A178235 A214447 A357541
KEYWORD
base,nonn
AUTHOR
Leroy Quet, Oct 13 2008
EXTENSIONS
Extended by R. J. Mathar and Ray Chandler, Oct 14 2008
STATUS
approved