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.

A091991 Minimal number of 1's that must be inserted into the binary representation of n to get a prime.

This page as a plain text file.
%I A091991 #15 Dec 18 2017 11:55:22
%S A091991 1,0,0,2,0,1,0,1,1,2,0,2,0,1,1,2,0,1,0,1,1,2,0,2,1,1,1,4,0,1,0,2,1,2,
%T A091991 1,1,0,2,1,2,0,2,0,1,1,3,0,1,1,1,1,2,0,1,2,1,3,3,0,3,0,2,1,3,1,2,0,1,
%U A091991 1,2,0,2,0,1,1,2,1,1,0,2,1,2,0,3,1,1,2,2,0,1,2,2,2,2,1,1,0,1,1,2,0,2
%N A091991 Minimal number of 1's that must be inserted into the binary representation of n to get a prime.
%C A091991 Insertion here means that the new 1-bit must come somewhere right of the most significant 1-bit. - _Antti Karttunen_, Dec 15 2017
%H A091991 Antti Karttunen, <a href="/A091991/b091991.txt">Table of n, a(n) for n = 1..16384</a>
%H A091991 <a href="/index/Bi#binary">Index entries for sequences related to binary expansion of n</a>
%F A091991 a(2*n) = a(4*n+1) + 1.
%F A091991 a(A005097(n)) = 1 - A010051(A005097(n)).
%F A091991 a(2^k)=A061712(k); a(2^k+1)=A061712(k-1)*(1-A010051(2^k+1));
%F A091991 a(2^k-1) = A000043(m+1) - k for A000043(m)<k<=A000043(m+1).
%e A091991 n = 25->'11001': A000040(16)=53->'110[1]01', therefore a(25)=1;
%e A091991 a(255)=a(2^8-1)=5, as 2^(8+5)-1=8191 is a Mersenne prime and 2^(8+i)-1 is not prime for i<5.
%o A091991 (PARI)
%o A091991 insert1bit(n,pos) = (((n>>pos)<<(1+pos))+(1<<pos)+bitand(n,(2^pos)-1));
%o A091991 binwidth(n) = { my(k=0); while(n,n>>=1;k++); k; };
%o A091991 A091991(n) = { if(1==n,return(1)); if(isprime(n),return(0)); if(!(n%2),return(1+A091991(1+n+n))); my(k,nexttries,prevtries = Set([n]), w = binwidth(n)-1); for(b=1,oo,nexttries = Set([]); for(t=1,length(prevtries), h = prevtries[t]; for(i=1,w,if(isprime(k=insert1bit(h,i)),return(b),nexttries = setunion(Set([k]),nexttries)))); prevtries = nexttries; w++);};
%o A091991 \\ _Antti Karttunen_, Dec 15 2017
%Y A091991 Cf. A000668, A014499, A108234.
%K A091991 nonn
%O A091991 1,4
%A A091991 _Reinhard Zumkeller_, Mar 17 2004