A071574 If n = k-th prime, a(n) = 2*a(k) + 1; if n = k-th nonprime, a(n) = 2*a(k).
0, 1, 3, 2, 7, 6, 5, 4, 14, 12, 15, 10, 13, 8, 28, 24, 11, 30, 9, 20, 26, 16, 29, 56, 48, 22, 60, 18, 25, 40, 31, 52, 32, 58, 112, 96, 21, 44, 120, 36, 27, 50, 17, 80, 62, 104, 57, 64, 116, 224, 192, 42, 49, 88, 240, 72, 54, 100, 23, 34, 61, 160, 124, 208, 114, 128, 19
Offset: 1
Examples
1 is the 1st nonprime, so a(1) = 2*a(1), therefore a(1) = 0. 2 is the 1st prime, so a(2) = 2*a(1)+1 = 2*0+1 = 1. 4 is the 2nd nonprime, so a(4) = 2*a(2) = 2*1 = 2.
Links
Crossrefs
Programs
-
Haskell
a071574 1 = 0 a071574 n = 2 * a071574 (if j > 0 then j + 1 else a049084 n) + 1 - signum j where j = a066246 n -- Reinhard Zumkeller, Feb 12 2014
-
Mathematica
a[1]=0; a[n_]:=If[PrimeQ[n],2*a[PrimePi[n]]+1,2*a[n-PrimePi[n]]];Table[a[n],{n,100}]
-
PARI
first(n) = my(res = vector(n), p); for(x=2, n, p=isprime(x); res[x]=2*res[x*!p-(-1)^p*primepi(x)]+p); res \\ Iain Fox, Oct 19 2018
-
Scheme
;; With memoizing definec-macro. (definec (A071574 n) (cond ((= 1 n) 0) ((= 1 (A010051 n)) (+ 1 (* 2 (A071574 (A000720 n))))) (else (* 2 (A071574 (+ 1 (A065855 n))))))) ;; Antti Karttunen, Apr 04 2015
Formula
a(1) = 0, and for n > 1, if A010051(n) = 1 [when n is a prime], a(n) = 1 + 2*a(A000720(n)), otherwise a(n) = 2*a(1 + A065855(n)). - Antti Karttunen, Apr 04 2015
Extensions
Mathematica program completed by Harvey P. Dale, Nov 28 2024
Comments