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.

Showing 1-3 of 3 results.

A164022 a(n) = the smallest prime that, when written in binary, starts with the substring of n in binary.

Original entry on oeis.org

2, 2, 3, 17, 5, 13, 7, 17, 19, 41, 11, 97, 13, 29, 31, 67, 17, 37, 19, 41, 43, 89, 23, 97, 101, 53, 109, 113, 29, 61, 31, 131, 67, 137, 71, 73, 37, 307, 79, 163, 41, 337, 43, 89, 181, 373, 47, 97, 197, 101, 103, 211, 53, 109, 223, 113, 229, 233, 59, 241, 61, 251, 127, 257
Offset: 1

Views

Author

Leroy Quet, Aug 08 2009

Keywords

Comments

The argument used to prove that A018800(n) always exists applies here also. - N. J. A. Sloane, Nov 14 2014

Examples

			4 in binary is 100. Looking at the binary numbers that begin with 100: 100 = 4 in decimal is composite; 1000 = 8 in decimal is composite; 1001 = 9 in decimal is composite; 10000 = 16 in decimal is composite. But 10001 = 17 in decimal is prime. So a(4) = 17.
		

Crossrefs

A018800 is the base-10 analog.
Row n=1 of A262365. Cf. A108234 (number of new bits), A208241 (proper substring).

Programs

  • Maple
    A164022 := proc(n) dgs2 := convert(n,base,2) ; ldgs := nops(dgs2) ; for i from 1 do p := ithprime(i) ; if p >= n then pdgs := convert(p,base,2) ; if [op(nops(pdgs)+1-ldgs.. nops(pdgs),pdgs)] = dgs2 then RETURN( p) ; fi; fi; od: end: seq(A164022(n),n=1..120) ; # R. J. Mathar, Sep 13 2009
  • Mathematica
    With[{s = Map[IntegerDigits[#, 2] &, Prime@ Range[10^4]]}, Table[Block[{d = IntegerDigits[n, 2]}, FromDigits[#, 2] &@ SelectFirst[s, Take[#, UpTo@ Length@ d] == d &]], {n, 64}]] (* Michael De Vlieger, Sep 23 2017 *)

Extensions

Corrected terms a(1) and a(2) (with help from Ray Chandler) Leroy Quet, Aug 16 2009
Extended by R. J. Mathar, Sep 13 2009

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

Original entry on oeis.org

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, 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, 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
Offset: 1

Views

Author

Reinhard Zumkeller, Mar 17 2004

Keywords

Comments

Insertion here means that the new 1-bit must come somewhere right of the most significant 1-bit. - Antti Karttunen, Dec 15 2017

Examples

			n = 25->'11001': A000040(16)=53->'110[1]01', therefore a(25)=1;
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.
		

Crossrefs

Programs

  • PARI
    insert1bit(n,pos) = (((n>>pos)<<(1+pos))+(1<>=1;k++); k; };
    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++);};
    \\ Antti Karttunen, Dec 15 2017

Formula

a(2*n) = a(4*n+1) + 1.
a(A005097(n)) = 1 - A010051(A005097(n)).
a(2^k)=A061712(k); a(2^k+1)=A061712(k-1)*(1-A010051(2^k+1));
a(2^k-1) = A000043(m+1) - k for A000043(m)A000043(m+1).

A338884 The smallest number of bits which need to be appended to the binary representation of n to reach a prime greater than n.

Original entry on oeis.org

1, 1, 1, 2, 1, 1, 2, 1, 1, 2, 1, 3, 2, 1, 1, 2, 2, 1, 2, 1, 1, 2, 1, 2, 2, 1, 2, 2, 1, 1, 2, 2, 1, 2, 1, 1, 2, 3, 1, 2, 1, 3, 2, 1, 2, 3, 2, 1, 2, 1, 1, 2, 1, 1, 2, 1, 2, 2, 2, 2, 3, 2, 1, 2, 1, 4, 2, 1, 1, 2, 3, 3, 2, 1, 1, 2, 2, 1, 2, 3, 1, 2, 1, 2, 3, 1, 2
Offset: 1

Views

Author

Ya-Ping Lu, Nov 13 2020

Keywords

Comments

a(n) is also the distance from a node to its first prime-number descendant in a binary tree defined as: root = 1 and, for any node n, the left child = 2*n and right child = 2*n + 1. The number of primes among the nodes of depth m is equal to A036378(m) for m>=2.

Crossrefs

Cf. A000040, A036378, A208241, A005097 (where a(n)=1).
Cf. A108234 (zero or more bits).

Programs

  • Python
    from sympy import isprime
    for n in range(1,101):
        a = 0
        k = i = 1
        while isprime(i) == 0:
            a += 1
            k = 2*k
            for i in range(k*n + 1, k*n + k):
                if isprime(i) == 1: break
        print(a)

Formula

a(n) = bitlength(A208241(n)) - bitlength(n), where bitlength = A070939. - Kevin Ryde, Nov 13 2020
Showing 1-3 of 3 results.