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.
%I A227321 #28 Aug 13 2013 06:13:57 %S A227321 3,3,3,3,4,3,3,3,4,3,3,5,3,8,3,3,4,5,3,11,3,3,3,5,4,3,10,3,3,11,3,17, %T A227321 4,3,5,3,3,7,14,3,4,15,3,23,3,3,5,11,4,3,5,5,3,19,3,3,3,8,5,21,3,32, %U A227321 14,3,4,3,3,15,3,5,5,25,3,38,7,3,6,3,3,13,4,3 %N A227321 a(n) is the least r>=3 such that the difference between the nearest r-gonal number >= n and n is an r-gonal number. %C A227321 The n-th r-gonal numbers is n((n-1)r-2(n-2))/2, such that 3-gonal numbers are triangular numbers, 4-gonal numbers are squares, etc. %H A227321 Peter J. C. Moses, <a href="/A227321/b227321.txt">Table of n, a(n) for n = 0..1999</a> %F A227321 If n is prime, then n == 1 or 2 mod (a(n)-2). If n >= 13 is the greater of a pair of twin primes (A006512), then a(n) = (n+3)/2. - _Vladimir Shevelev_, Aug 07 2013 %t A227321 rGonalQ[r_,0]:=True; rGonalQ[r_,n_]:=IntegerQ[(Sqrt[((8r-16)n+(r-4)^2)]+r-4)/(2r-4)]; nthrGonal[r_,n_]:=(n (r-2)(n-1))/2+n; nextrGonal[r_,n_]:=nthrGonal[r,Ceiling[(Sqrt[((8r-16)n+(r-4)^2)]+r-4)/(2r-4)]]; (* next r-gonal number greater than or equal to n *) Table[NestWhile[#+1&,3,!rGonalQ[#,nextrGonal[#,n]-n]&],{n,0,99}] (* _Peter J. C. Moses_, Aug 03 2013 *) %Y A227321 Cf. A000217 (r=3), A000290 (r=4), A000326 (r=5), A000384 (r=6), A000566 (r=7), A000567 (r=8), A001106-7 (r=9,10), A051682 (r=11), A051624 (r=12), A051865-A051876 (r=13-24). %K A227321 nonn %O A227321 0,1 %A A227321 _Vladimir Shevelev_, Jul 30 2013 %E A227321 More terms from _Peter J. C. Moses_, Jul 30 2013