cp's OEIS Frontend

This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.

A333877 a(n) is the largest prime 2^(n-1) <= p < 2^n maximizing the Hamming weight of all primes in this interval.

This page as a plain text file.
%I A333877 #27 Aug 17 2024 11:13:43
%S A333877 3,7,13,31,61,127,251,509,1021,2039,4093,8191,16381,32749,65519,
%T A333877 131071,262139,524287,1048573,2097143,4194301,8388587,16777213,
%U A333877 33546239,67108859,134217467,260046847,536870909,1073741567,2147483647,4294967291,8589934583,16911433727
%N A333877 a(n) is the largest prime 2^(n-1) <= p < 2^n maximizing the Hamming weight of all primes in this interval.
%C A333877 This differs from A014234 at n=1 and then first at n=16: a(16) = 65519 != 65521 = A014234(16). - _Alois P. Heinz_, Apr 25 2020
%H A333877 Chai Wah Wu, <a href="/A333877/b333877.txt">Table of n, a(n) for n = 2..998</a>
%p A333877 a:= proc(n) option remember; local i, p;
%p A333877       for i from 0 do p:= max(select(isprime, map(l-> add(l[j]*
%p A333877         2^(j-1), j=1..n), combinat[permute]([1$(n-i),0$i]))));
%p A333877         if p>0 then break fi
%p A333877       od; p
%p A333877     end:
%p A333877 seq(a(n), n=2..30);  # _Alois P. Heinz_, Apr 23 2020
%t A333877 a[n_] := a[n] = MaximalBy[{#, DigitCount[#, 2, 1]}& /@ Select[Range[ 2^(n-1), 2^n-1], PrimeQ], Last][[-1, 1]];
%t A333877 Table[Print[n, " ", a[n]]; a[n], {n, 2, 30}] (* _Jean-François Alcover_, Nov 09 2020 *)
%o A333877 (PARI) for(n=2, 30, my(hmax=0,pmax); forprime(p=2^(n-1), 2^n, my(h=hammingweight(p)); if(h>=hmax,pmax=p;hmax=h)); print1(pmax,", "))
%o A333877 (Python)
%o A333877 from sympy import isprime
%o A333877 from sympy.utilities.iterables import multiset_permutations
%o A333877 def A333877(n):
%o A333877     for i in range(n-1,-1,-1):
%o A333877         q = 2**n-1
%o A333877         for d in multiset_permutations('0'*i+'1'*(n-1-i)):
%o A333877             p = q-int(''.join(d),2)
%o A333877             if isprime(p):
%o A333877                 return p # _Chai Wah Wu_, Apr 08 2020
%Y A333877 Cf. A014234, A091937, A091938, A333876, A333879.
%K A333877 nonn
%O A333877 2,1
%A A333877 _Hugo Pfoertner_, Apr 08 2020