login
A354973
a(0)=0; for n > 0, a(n) = 2*a(n-1) if n-1 is prime, a(n-1) + 1 otherwise.
0
0, 1, 2, 4, 8, 9, 18, 19, 38, 39, 40, 41, 82, 83, 166, 167, 168, 169, 338, 339, 678, 679, 680, 681, 1362, 1363, 1364, 1365, 1366, 1367, 2734, 2735, 5470, 5471, 5472, 5473, 5474, 5475, 10950, 10951, 10952, 10953, 21906, 21907, 43814, 43815, 43816, 43817, 87634
OFFSET
0,3
FORMULA
a(n) = A110299(k) - 2^k + n + 1, where k = primepi(n-1) and taking A110299(0) = 0. - Kevin Ryde, Jun 22 2022
EXAMPLE
5 is prime, so a(6) = 2*a(5) = 2*9 = 18.
6 is not prime, so a(7) = a(6) + 1 = 18 + 1 = 19.
MATHEMATICA
a[0] = 0; a[n_] := a[n] = If[PrimeQ[n - 1], 2*a[n - 1], a[n - 1] + 1]; Array[a, 50, 0] (* Amiram Eldar, Jun 21 2022 *)
PROG
(Python)
from sympy import isprime
a = [0]; [a.append(2*a[-1] if isprime(n) else a[-1]+1) for n in range(48)]
print(a) # Michael S. Branicky, Jun 21 2022
(PARI) a(n) = my(k=primepi(n-1)); fromdigits(primes(k), 2) - 1<<k + n + 1; \\ Kevin Ryde, Jun 22 2022
CROSSREFS
Cf. A110299.
Sequence in context: A294441 A246347 A255717 * A177404 A046685 A248741
KEYWORD
nonn
AUTHOR
Ben White, Jun 14 2022
STATUS
approved