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.

A071574 If n = k-th prime, a(n) = 2*a(k) + 1; if n = k-th nonprime, a(n) = 2*a(k).

This page as a plain text file.
%I A071574 #55 Mar 11 2025 11:41:17
%S A071574 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,
%T A071574 60,18,25,40,31,52,32,58,112,96,21,44,120,36,27,50,17,80,62,104,57,64,
%U A071574 116,224,192,42,49,88,240,72,54,100,23,34,61,160,124,208,114,128,19
%N A071574 If n = k-th prime, a(n) = 2*a(k) + 1; if n = k-th nonprime, a(n) = 2*a(k).
%C A071574 The recursion start is implicit in the rule, since the rule demands that a(1)=2*a(1). All other terms are defined through terms for smaller indices until a(1) is reached.
%C A071574 a(n) is a bijective mapping from the positive integers to the nonnegative integers. Given the value of a(n), you can get back to n using the following algorithm:
%C A071574 Start with an initial value of k=1 and write a(n) in binary representation. Then for each bit, starting with the most significant one, do the following: - if the bit is 1, replace k by the k-th prime - if the bit is 0, replace k by the k-th nonprime. After you processed the last (i.e. least significant) bit of a(n), you've got n=k.
%C A071574 Example: From a(n) = 12 = 1100_2, you get 1->2->3=>6=>10; a(10)=12. Here each "->" is a step due to binary digit 1; each "=>" is a step due to binary digit 0.
%C A071574 The following sequences all appear to have the same parity (with an extra zero term at the start of A010051): A010051, A061007, A035026, A069754, A071574. - _Jeremy Gardiner_, Aug 09 2002. (At least with this sequence the identity a(n) = A010051(n) mod 2 is obvious, because each prime is mapped to an odd number and each composite to an even number. - _Antti Karttunen_, Apr 04 2015)
%C A071574 For n > 1: a(n) = 2 * a(if i > 0 then i else A066246(n) + 1) + A057427(i) with i = A049084(n). - _Reinhard Zumkeller_, Feb 12 2014
%C A071574 A237739(a(n)) = n; a(A237739(n)) = n. - _Reinhard Zumkeller_, Apr 30 2014
%H A071574 T. D. Noe, <a href="/A071574/b071574.txt">Table of n, a(n) for n = 1..10000</a>
%H A071574 <a href="/index/Per#IntegerPermutation">Index entries for sequences that are permutations of the natural numbers</a>
%F A071574 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
%e A071574 1 is the 1st nonprime, so a(1) = 2*a(1), therefore a(1) = 0.
%e A071574 2 is the 1st prime, so a(2) = 2*a(1)+1 = 2*0+1 = 1.
%e A071574 4 is the 2nd nonprime, so a(4) = 2*a(2) = 2*1 = 2.
%t A071574 a[1]=0; a[n_]:=If[PrimeQ[n],2*a[PrimePi[n]]+1,2*a[n-PrimePi[n]]];Table[a[n],{n,100}]
%o A071574 (Haskell)
%o A071574 a071574 1 = 0
%o A071574 a071574 n = 2 * a071574 (if j > 0 then j + 1 else a049084 n) + 1 - signum j
%o A071574             where j = a066246 n
%o A071574 -- _Reinhard Zumkeller_, Feb 12 2014
%o A071574 (Scheme)
%o A071574 ;; With memoizing definec-macro.
%o A071574 (definec (A071574 n) (cond ((= 1 n) 0) ((= 1 (A010051 n)) (+ 1 (* 2 (A071574 (A000720 n))))) (else (* 2 (A071574 (+ 1 (A065855 n)))))))
%o A071574 ;; _Antti Karttunen_, Apr 04 2015
%o A071574 (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
%Y A071574 Inverse: A237739.
%Y A071574 Cf. A000720 (pi), A049084, A065855, A066246.
%Y A071574 Compare also to the permutation A246377.
%Y A071574 Same parity: A010051, A061007, A035026, A069754.
%K A071574 easy,nice,nonn,look
%O A071574 1,3
%A A071574 Christopher Eltschka (celtschk(AT)web.de), May 31 2002
%E A071574 Mathematica program completed by _Harvey P. Dale_, Nov 28 2024