A200975 Numbers on the diagonals in Ulam's spiral.
1, 3, 5, 7, 9, 13, 17, 21, 25, 31, 37, 43, 49, 57, 65, 73, 81, 91, 101, 111, 121, 133, 145, 157, 169, 183, 197, 211, 225, 241, 257, 273, 289, 307, 325, 343, 361, 381, 401, 421, 441, 463, 485, 507, 529, 553, 577, 601, 625, 651, 677, 703, 729, 757, 785, 813, 841, 871, 901
Offset: 1
Examples
The numbers between ** are in this sequence. . *21*--22---23---24--*25* | | 20 *7*---8---*9*--10 | | | | | | 19 6 *1*---2 11 | | | | | | | | 18 *5*---4---*3* 12 | | | | *17*--16---15---14--*13*
Links
- Todd Silvestri, Table of n, a(n) for n = 1..1000
- Project Euler, Problem 28: Number spiral diagonals
- Index entries for linear recurrences with constant coefficients, signature (2,-1,0,1,-2,1).
Crossrefs
Programs
-
Mathematica
Sort@ Flatten@ Table[4n^2 + (2j - 4)n + 1, {j, 0, 3}, {n, 16}] (* Robert G. Wilson v, Jul 10 2014 *) a[n_Integer/;n>0]:=Quotient[2 n (n+2)+(-1)^n-4 Mod[n^2 (3 n+2),4,-1]+7,8] (* Todd Silvestri, Oct 25 2014 *)
-
PARI
al(n)=local(r=vector(n),j);r[1]=1;for(k=2,n,r[k]=r[k-1]+(k+2)\4*2);r /* Franklin T. Adams-Watters, Nov 26 2011 */
-
Python
# prints all numbers on the diagonals of a sq*sq spiral sq = 5 d = 1 while 2*d - 1 < sq: print(4*d*d - 4*d +1) print(4*d*d - 4*d +1 + 1* 2* d) print(4*d*d - 4*d +1 + 2* 2* d) print(4*d*d - 4*d +1 + 3* 2* d) d += 1 print(sq*sq)
Formula
a(4n) = 4n^2 + 2n + 1; a(4n+1) = 4n^2 + 4n + 1; a(4n+2) = 4n^2 + 6n + 3; a(4n+3) = 4n^2 + 8n + 5. [corrected by James Mitchell, Dec 31 2017]
G.f.: -x*(1+x+x^5-x^4) / ( (1+x)*(x^2+1)*(x-1)^3 ). - R. J. Mathar, Nov 28 2011
a(n) = (2*n*(n+2)+(-1)^n-4*sin((Pi*n)/2)+7)/8 = (A249356(n)+7)/8. - Todd Silvestri, Oct 25 2014
a(n) = floor_(n*(n+2)/4) + floor_(n(mod 4)/3) + 1. - Bob Selcoe, Oct 27 2014
Extensions
Edited with more terms by Franklin T. Adams-Watters, Nov 26 2011
Comments