A038722 Take the sequence of natural numbers (A000027) and reverse successive subsequences of lengths 1,2,3,4,... .
1, 3, 2, 6, 5, 4, 10, 9, 8, 7, 15, 14, 13, 12, 11, 21, 20, 19, 18, 17, 16, 28, 27, 26, 25, 24, 23, 22, 36, 35, 34, 33, 32, 31, 30, 29, 45, 44, 43, 42, 41, 40, 39, 38, 37, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 66, 65, 64, 63, 62, 61, 60, 59, 58, 57, 56, 78, 77, 76
Offset: 1
Examples
The rectangular array view is 1 2 4 7 11 16 22 29 37 46 3 5 8 12 17 23 30 38 47 57 6 9 13 18 24 31 39 48 58 69 10 14 19 25 32 40 49 59 70 82 15 20 26 33 41 50 60 71 83 96 21 27 34 42 51 61 72 84 97 111 28 35 43 52 62 73 85 98 112 127 36 44 53 63 74 86 99 113 128 144 45 54 64 75 87 100 114 129 145 162 55 65 76 88 101 115 130 146 163 181
References
- Suggested by correspondence with Michael Somos.
- R. Honsberger, "Ingenuity in Mathematics", Table 10.4 on page 87.
Links
- Hieronymus Fischer, Table of n, a(n) for n = 1..11401
- Michael Somos, Introduction to Ramanujan theta functions
- Eric Weisstein's World of Mathematics, Ramanujan Theta Functions
- Index entries for sequences that are permutations of the natural numbers
Crossrefs
Programs
-
Haskell
a038722 n = a038722_list !! (n-1) a038722_list = concat a038722_tabl a038722_tabl = map reverse a000027_tabl a038722_row n = a038722_tabl !! (n-1) -- Reinhard Zumkeller, Nov 08 2013
-
Mathematica
(* Program generates dispersion array T of the increasing sequence f[n] *) r=40; r1=12; c=40; c1=12; f[n_] := Floor[n+1/2+Sqrt[2n]] (* complement of column 1 *) mex[list_] := NestWhile[#1 + 1 &, 1, Union[list][[#1]] <= #1 &, 1, Length[Union[list]]] rows = {NestList[f, 1, c]}; Do[rows = Append[rows, NestList[f, mex[Flatten[rows]], r]], {r}]; t[i_, j_] := rows[[i, j]]; TableForm[Table[t[i, j], {i, 1, r1}, {j, 1, c1}]] (* A038722 array *) Flatten[Table[t[k, n - k + 1], {n, 1, c1}, {k, 1, n}]] (* A038722 sequence *) (* Clark Kimberling, Jun 06 2011, corrected Jan 26 2025 *) Table[ n, {m, 12}, {n, m (m + 1)/2, m (m - 1)/2 + 1, -1}] // Flatten (* or *) Table[ Ceiling[(Sqrt[8 n + 1] - 1)/2]^2 - n + 1, {n, 78}] (* Robert G. Wilson v, Jun 27 2014 *) With[{nn=20},Reverse/@TakeList[Range[(nn(1+nn))/2],Range[nn]]//Flatten] (* Requires Mathematica version 11 or later *) (* Harvey P. Dale, Dec 14 2017 *)
-
PARI
a(n)=local(t=floor(1/2+sqrt(2*n))); if(n<1, 0, t^2-n+1) /* Paul D. Hanna */
Formula
a(n) = (sqrt(2n-1) - 1/2)*(sqrt(2n-1) + 3/2) - n + 2 = A061579(n-1) + 1. Seen as a square table by antidiagonals, T(n, k) = k + (n+k-1)*(n+k-2)/2, i.e., the transpose of A000027 as a square table.
G.f.: g(x) = (x/(1-x))*(psi(x) - x/(1-x) + 2*Sum_{k>=0} k*x^(k*(k+1)/2)) where psi(x) = Sum_{k>=0} x^(k*(k+1)/2) = (1/2)*x^(-1/8)*theta_2(0,x^(1/2)) is a Ramanujan theta function. - Hieronymus Fischer, Aug 08 2007
a(n) = floor(sqrt(2*n) + 1/2)^2 - n + 1. - Clark Kimberling, Jun 05 2011; corrected by Paul D. Hanna, Jun 27 2011
From Hieronymus Fischer, Apr 30 2012: (Start)
a(n) = a(n-1)-1, if a(n-1)-1 > 0 is not in the set {a(k)| 1<=k
a(n) = n for n = 2k(k+1)+1, k >= 0.
a(n+1) = (m+2)(m+3)/2, if 8a(n)-7 is a square of an odd number, otherwise a(n+1) = a(n)-1, where m = (sqrt(8a(n)-7)-1)/2.
a(n) = ceiling((sqrt(8n+1)-1)/2)^2 - n + 1. (End)
G.f. as rectangular array: x*y*(1 - (1 + x)*y + (1 - x + x^2)*y^2)/((1 - x)^3*(1 - y)^3). - Stefano Spezia, Dec 25 2022
A090861 Permutation of natural numbers arising from a spiral.
1, 6, 5, 4, 3, 2, 9, 8, 7, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 25, 24, 23, 22, 21, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 49, 48, 47, 46, 45, 44, 43, 72, 71, 70, 69, 68, 67, 66, 65, 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50
Offset: 1
Comments
Write out the natural numbers in a square counterclockwise spiral:
.
17--16--15--14--13
| |
18 5---4---3 12
| | | |
19 6 1---2 11
| | |
20 7---8---9--10
|
21--22--23--24--25
.
Now read off the numbers in a clockwise spiral: 1 -> 6 -> 5 -> 4 -> 3 -> 2 -> 9 -> etc.
Links
- Eric M. Schmidt, Table of n, a(n) for n = 1..1000
Programs
-
Mathematica
With[{x = Floor[(Floor[Sqrt[n-1]]+1)/2]}, Table[8*x^2-n+2 +x*If[n <= 4*x^2+2*x, -2, 6], {n, 1, 75}]] (* G. C. Greubel, Feb 05 2019 *)
-
PARI
{s(n)=floor((floor(sqrt(n-1)) +1)/2)}; for(n=1,75, print1(8*s(n)^2 -n +2 +s(n)*if(n<= 2*s(n)*(2*s(n)+1), -2, 6), ", ")) \\ G. C. Greubel, Feb 05 2019
-
Sage
def a(n): x = (isqrt(n-1)+1)//2 return 8*x^2 + (-2 if n <= 4*x^2 + 2*x else 6)*x + 2 - n [a(n) for n in (1..75)] # Eric M. Schmidt, May 18 2016
Extensions
Offset corrected by Eric M. Schmidt, May 18 2016
A090915 Permutation of natural numbers arising from a square spiral.
1, 8, 7, 6, 5, 4, 3, 2, 9, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 25, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 49, 80, 79, 78, 77, 76, 75, 74, 73, 72, 71, 70, 69, 68, 67, 66, 65, 64, 63, 62, 61, 60, 59, 58
Offset: 1
Comments
Write out the natural numbers in a square counterclockwise spiral:
.
17--16--15--14--13
| |
18 5---4---3 12
| | | |
19 6 1---2 11
| | |
20 7---8---9--10
|
21--22--23--24--25
.
Now read off the numbers in a square clockwise spiral: 1 -> 8 -> 7 -> 6 -> 5 -> 4 -> 3 -> 2 -> 9 -> etc.
Links
- Eric M. Schmidt, Table of n, a(n) for n = 1..1000
Programs
-
Mathematica
With[{x = Floor[(Floor[Sqrt[n-1]]+1)/2]}, Table[If[n==(2*x+1)^2, n, 8*x^2 -n+2], {n, 1, 75}]] (* G. C. Greubel, Feb 05 2019 *)
-
PARI
{s(n) = ((sqrtint(n-1)+1)/2)\1}; for(n=1,75, print1(if(n == (2*s(n)+1)^2, n, 8*s(n)^2-n+2), ", ")) \\ G. C. Greubel, Feb 05 2019
-
Sage
def a(n): x = (isqrt(n-1)+1)//2 return n if n == (2*x+1)^2 else 8*x^2 + 2 - n [a(n) for n in (1..75)] # Eric M. Schmidt, May 18 2016
Extensions
Offset corrected by Eric M. Schmidt, May 18 2016
A090925 Permutation of natural numbers arising from a square spiral.
1, 4, 5, 6, 7, 8, 9, 2, 3, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 10, 11, 12, 13, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 26, 27, 28, 29, 30, 31, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80
Offset: 1
Comments
Write out the natural numbers in a square counterclockwise spiral:
.
17--16--15--14--13
| |
18 5---4---3 12
| | | |
19 6 1---2 11
| | |
20 7---8---9--10
|
21--22--23--24--25
.
Now read off the numbers in a square counterclockwise spiral: 1 -> 4 -> 5 -> 6 -> 7 -> 8 -> 9 -> 2 -> 3 -> 14 -> etc.
Links
- Eric M. Schmidt, Table of n, a(n) for n = 1..1000
Programs
-
Mathematica
With[{x = Floor[(Floor[Sqrt[n-1]]+1)/2]}, Table[If[n+2*x <= (2*x+1)^2, n +2*x, n-6*x], {n, 1, 75}]] (* G. C. Greubel, Feb 05 2019 *)
-
PARI
{s(n) = ((sqrtint(n-1)+1)/2)\1}; for(n=1,75, print1(if(n+2*s(n) <= (2*s(n)+1)^2, n +2*s(n), n - 6*s(n)), ", ")) \\ G. C. Greubel, Feb 05 2019
-
Sage
def a(n): x = (isqrt(n-1)+1)//2 return n + 2*x if n + 2*x <= (2*x+1)^2 else n - 6*x [a(n) for n in (1..75)] # Eric M. Schmidt, May 18 2016
Extensions
Offset corrected by Eric M. Schmidt, May 18 2016
A090928 Permutation of natural numbers arising from a square spiral.
1, 6, 7, 8, 9, 2, 3, 4, 5, 18, 19, 20, 21, 22, 23, 24, 25, 10, 11, 12, 13, 14, 15, 16, 17, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 50, 51, 52, 53, 54, 55, 56
Offset: 1
Comments
Write out the natural numbers in a square counterclockwise spiral:
.
17--16--15--14--13
| |
18 5---4---3 12
| | | |
19 6 1---2 11
| | |
20 7---8---9--10
|
21--22--23--24--25
.
Now read off the numbers in a counterclockwise spiral: 1 -> 6 -> 7 -> 8 -> 9 -> 2 -> 3 -> 4 -> 5 -> 18 -> etc.
Links
Programs
-
Mathematica
With[{x = Floor[(Floor[Sqrt[n-1]]+1)/2]}, Table[If[n +4*x <= (2*x+1)^2, n+4*x, n-4*x], {n, 1, 75}]] (* G. C. Greubel, Feb 05 2019 *)
-
PARI
{s(n) = ((sqrtint(n-1)+1)/2)\1}; for(n=1,75, print1(if(n+4*s(n) <= (2*s(n)+1)^2, n +4*s(n), n - 4*s(n)), ", ")) \\ G. C. Greubel, Feb 05 2019
-
Sage
def a(n): x = (isqrt(n-1)+1)//2 return n + 4*x if n + 4*x <= (2*x+1)^2 else n - 4*x [a(n) for n in (1..75)] # Eric M. Schmidt, May 18 2016
Formula
Extensions
Offset corrected by Eric M. Schmidt, May 18 2016
A090929 Permutation of natural numbers arising from a square spiral.
1, 8, 9, 2, 3, 4, 5, 6, 7, 22, 23, 24, 25, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 44, 45, 46, 47, 48, 49, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 74, 75, 76, 77, 78, 79, 80, 81, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64
Offset: 1
Comments
Write out the natural numbers in a square counterclockwise spiral:
.
17--16--15--14--13
| |
18 5---4---3 12
| | | |
19 6 1---2 11
| | |
20 7---8---9--10
|
21--22--23--24--25
.
Now read off the numbers in a counterclockwise spiral: 1 -> 8 -> 9 -> 2 -> 3 -> 4 -> 5 -> 6 -> 7 -> 22 -> etc.
Links
- Eric M. Schmidt, Table of n, a(n) for n = 1..1000
Programs
-
Mathematica
With[{x = Floor[(Floor[Sqrt[n-1]] +1)/2]}, Table[If[n +6*x <= (2*x+1)^2, n +6*x, n -2*x], {n, 1, 75}]] (* G. C. Greubel, Feb 05 2019 *)
-
PARI
{s(n) = ((sqrtint(n-1)+1)/2)\1}; for(n=1,75, print1(if(n+6*s(n) <= (2*s(n)+1)^2, n +6*s(n), n - 2*s(n)), ", ")) \\ G. C. Greubel, Feb 05 2019
-
Sage
def a(n): x = (isqrt(n-1)+1)//2 return n + 6*x if n + 6*x <= (2*x+1)^2 else n - 2*x [a(n) for n in (1..75)] # Eric M. Schmidt, May 18 2016
Extensions
Offset corrected by Eric M. Schmidt, May 18 2016
A090930 Permutation of natural numbers arising from a square spiral.
1, 2, 9, 8, 7, 6, 5, 4, 3, 12, 11, 10, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 30, 29, 28, 27, 26, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 56, 55, 54, 53, 52, 51, 50, 81, 80, 79, 78, 77, 76, 75, 74, 73, 72, 71, 70, 69, 68, 67, 66
Offset: 1
Comments
Write out the natural numbers in a square counterclockwise spiral:
.
17--16--15--14--13
| |
18 5---4---3 12
| | | |
19 6 1---2 11
| | |
20 7---8---9--10
|
21--22--23--24--25
.
Now read off the numbers in a clockwise spiral: 1 -> 2 -> 9 -> 8 -> 7 -> 6 -> 5 -> 4 -> 3 -> 12 -> etc.
Links
- Eric M. Schmidt, Table of n, a(n) for n = 1..1000
Programs
-
Mathematica
With[{x = Floor[(Floor[Sqrt[n-1]] +1)/2]}, Table[8*x^2 -n +2 +x*If[n <= 4*x^2 -2*x, -6, 2], {n, 1, 75}]] (* G. C. Greubel, Feb 05 2019 *)
-
PARI
{s(n) = ((sqrtint(n-1)+1)/2)\1}; for(n=1,75, print1(8*s(n)^2 -n +2 +s(n)*if(n <= 2*s(n)*(2*s(n)-1), -6, 2), ", ")) \\ G. C. Greubel, Feb 05 2019
-
Sage
def a(n): x = (isqrt(n-1)+1)//2 return 8*x^2 + (-6 if n <= 4*x^2 - 2*x else 2)*x + 2 - n [a(n) for n in (1..75)] # Eric M. Schmidt, May 18 2016
Extensions
Offset corrected by Eric M. Schmidt, May 18 2016
A182194 a(1)=2, a(n)=a(n-1)^2 if the minimal natural number > 1 not yet in the sequence is greater than a(n-1), else a(n)=a(n-1)-1.
2, 4, 3, 9, 8, 7, 6, 5, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81, 80, 79, 78, 77, 76, 75, 74, 73, 72, 71, 70, 69, 68, 67, 66, 65, 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54
Offset: 1
Keywords
Comments
A reordering of the natural numbers > 1.
The sequence is quasi self-inverse in that a(a(n-1)-1)=n.
Examples
a(2)=4=a(1)^2, since 3>2=a(1) is the minimal number not yet in the sequence (because of a(1)=2); a(15)=19=a(14)-1, since the minimal number not yet in the sequence (=10) is <=a(14)=20. a(10^4)=b(8)+b(7)-10^4-2=877. a(10^6)=b(10)+b(9)-10^6-2= 103539133.
Links
- Hieronymus Fischer, Table of n, a(n) for n = 1..10200
Formula
a(n)=a(n-1)-1, if a(n-1)-1 > 1 is not in the set {a(k)| 1<=k<=n-1}, else a(n)=a(n-1)^2.
a(a(n)-1)=n+1.
If we define b(1)=2, b(2)=3, b(k)=b(k-2)^2+1, we get the sequence 2, 3, 5, 10, 26, 101, 677, 10202, 458330, 104080805, …. The b(k) are those terms a(n) of the original sequence for which a(n+1)=a(n)^2.
With these b(k) we obtain for k>1:
a(b(k)-2)=b(k-1),
a(b(k)-1)=b(k-1)^2.
a(b(k))=b(k-1)^2 - 1.
a(n)=b(m)+b(m-1)-n-2, where m is the least index such that b(m)>n+1 (valid for n>=1).
A210882
a(1)=1, a(n)=a(n-1)-1 if a(n-1)-1 > 0 is not in the set {a(k)| 1<=k
1, 2, 3, 5, 4, 7, 6, 11, 10, 9, 8, 13, 12, 17, 16, 15, 14, 19, 18, 23, 22, 21, 20, 29, 28, 27, 26, 25, 24, 31, 30, 37, 36, 35, 34, 33, 32, 41, 40, 39, 38, 43, 42, 47, 46, 45, 44, 53, 52, 51, 50, 49, 48, 59, 58, 57, 56, 55, 54, 61, 60, 67, 66, 65, 64, 63, 62, 71
Offset: 1
Keywords
Comments
A reordering of the natural numbers.
The sequence is self-inverse in that a(a(n))=n.
If n is a prime, then a(n+1) is the next prime > n. Hence, the subsequence 2, a(2+1), a(a(2+1)+1), a(a(a(2+1)+1)+1), a(a(a(a(2+1)+1)+1)+1), ... generates the sequence of primes A000040.
Examples
a(4)=5, since 5 is the least prime > a(1), a(2), a(3), and the minimal number not yet in the sequence (=4) is greater than 3=a(3). a(5)=4, since 4 is not in the set {1,2,3,5}={a(k)| 1<=k<n}. 7=p(4)=a(p(3)+1)=a(a(p(2)+1)+1)= a(a(a(p(1)+1)+1)+1)= a(a(a(2+1)+1)+1).
Links
- Hieronymus Fischer, Table of n, a(n) for n = 1..10000
Formula
a(1)=1, a(n)=p (where p is the least prime number > a(k) for 1<=k
a(n)<>n for all n>3.
p(n+1)=a(p(n)+1), where p(n) is the n-th prime.
a(n+1)=p(m+2), if a(n)-1 is the m-th prime, else a(n+1)=a(n)-1, for n>2.
a(n)=p(m)+p(m-1)-n+1, where m is the least index such that p(m)>n-1 (valid for n>2).
Comments