|
|
A071574
|
|
If n = k-th prime, a(n) = 2*a(k) + 1; if n = k-th nonprime, a(n) = 2*a(k).
|
|
10
|
|
|
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
(list;
graph;
refs;
listen;
history;
text;
internal format)
|
|
|
OFFSET
|
1,3
|
|
COMMENTS
|
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.
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:
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.
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.
|
|
LINKS
|
|
|
FORMULA
|
|
|
EXAMPLE
|
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.
|
|
MATHEMATICA
|
a[1] = 0 a[n_] := If[PrimeQ[n], 2*a[PrimePi[n]] + 1, 2*a[n - PrimePi[n]]]
|
|
PROG
|
(Haskell)
a071574 1 = 0
a071574 n = 2 * a071574 (if j > 0 then j + 1 else a049084 n) + 1 - signum j
where j = a066246 n
(Scheme, with memoizing definec-macro)
(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
|
|
CROSSREFS
|
Compare also to the permutation A246377.
|
|
KEYWORD
|
|
|
AUTHOR
|
Christopher Eltschka (celtschk(AT)web.de), May 31 2002
|
|
STATUS
|
approved
|
|
|
|