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.

Showing 1-10 of 11 results. Next

A050683 Number of nonzero palindromes of length n.

Original entry on oeis.org

9, 9, 90, 90, 900, 900, 9000, 9000, 90000, 90000, 900000, 900000, 9000000, 9000000, 90000000, 90000000, 900000000, 900000000, 9000000000, 9000000000, 90000000000, 90000000000, 900000000000, 900000000000, 9000000000000
Offset: 1

Views

Author

Patrick De Geest, Aug 15 1999

Keywords

Comments

In general the number of base k palindromes with n digits is (k-1)*k^floor((n-1)/2). (See A117855 or A225367 for an explanation.) - Henry Bottomley, Aug 14 2000
This sequence does not count 0 as palindrome with 1 digit, see A070252 = (10,9,90,90,...) for the variant which does. - M. F. Hasler, Nov 16 2008

Crossrefs

Cf. A016116 for numbers of binary palindromes, A016115 for prime palindromes.
Cf. A117855 for the base 3 version, and A225367 for a variant.

Programs

  • GAP
    a:=[9,9];; for n in [3..30] do a[n]:=10*a[n-2]; od; a; # Muniru A Asiru, Oct 07 2018
    
  • Magma
    [9*10^Floor((n-1)/2): n in [1..30]]; // Vincenzo Librandi, Aug 16 2011
    
  • Maple
    seq(9*10^floor((n-1)/2),n=1..30); # Muniru A Asiru, Oct 07 2018
  • Mathematica
    With[{c=9*10^Range[0,20]},Riffle[c,c]] (* or *) LinearRecurrence[{0,10},{9,9},40] (* Harvey P. Dale, Dec 15 2013 *)
  • PARI
    A050683(n)=9*10^((n-1)\2) \\ M. F. Hasler, Nov 16 2008
    
  • PARI
    \\ using M. F. Hasler's is_A002113(n) from A002113
    is_A002113(n)={Vecrev(n=digits(n))==n}
    for(n=1,8,j=0;for(k=10^(n-1),10^n-1,if(is_A002113(k),j++));print1(j,", ")) \\ Hugo Pfoertner, Oct 03 2018
    
  • PARI
    is_palindrome(x)={my(d=digits(x));for(k=1,#d\2,if(d[k]!=d[#d+1-k],return(0)));return(1)}
    for(n=1,8,j=0;for(k=10^(n-1),10^n-1,if(is_palindrome(k),j++));print1(j,", ")) \\ Hugo Pfoertner, Oct 02 2018
    
  • PARI
    a(n) = if(n<3, 9, 10*a(n-2)); \\ Altug Alkan, Oct 03 2018
    
  • Python
    def A050683(n): return 9*10**(n-1>>1) # Chai Wah Wu, Jul 30 2025

Formula

a(n) = 9*10^floor((n-1)/2).
From Colin Barker, Apr 06 2012: (Start)
a(n) = 10*a(n-2).
G.f.: 9*x*(1+x)/(1-10*x^2). (End)
E.g.f.: 9*(cosh(sqrt(10)*x) + sqrt(10)*sinh(sqrt(10)*x) - 1)/10. - Stefano Spezia, Jun 11 2022

A117855 Number of nonzero palindromes of length n (in base 3).

Original entry on oeis.org

2, 2, 6, 6, 18, 18, 54, 54, 162, 162, 486, 486, 1458, 1458, 4374, 4374, 13122, 13122, 39366, 39366, 118098, 118098, 354294, 354294, 1062882, 1062882, 3188646, 3188646, 9565938, 9565938, 28697814, 28697814, 86093442, 86093442, 258280326, 258280326, 774840978
Offset: 1

Views

Author

Martin Renner, May 02 2006

Keywords

Comments

See A225367 for the sequence that counts all base 3 palindromes, including 0 (and thus also the number of n-digit terms in A006072). -- A nonzero palindrome of length L=2k-1 or of length L=2k is determined by the first k digits, which then determine the last k digits by symmetry. Since the first digit cannot be 0, there are 2*3^(k-1) possibilities. - M. F. Hasler, May 05 2013
From Gus Wiseman, Oct 18 2023: (Start)
Also the number of subsets of {1..n} with n not the sum of two subset elements (possibly the same). For example, the a(0) = 1 through a(4) = 6 subsets are:
{} {} {} {} {}
{1} {2} {1} {1}
{2} {3}
{3} {4}
{1,3} {1,4}
{2,3} {3,4}
For subsets with no subset summing to n we have A365377.
Requiring pairs to be distinct gives A068911, complement A365544.
The complement is counted by A366131.
(End) [Edited by Peter Munn, Nov 22 2023]

Examples

			The a(3)=6 palindromes of length 3 are: 101, 111, 121, 202, 212, and 222. - _M. F. Hasler_, May 05 2013
		

Crossrefs

Cf. A050683 and A070252.
Bisections are both A025192.
A093971/A088809/A364534 count certain types of sum-full subsets.
A108411 lists powers of 3 repeated, complement A167936.

Programs

  • Mathematica
    With[{c=NestList[3#&,2,20]},Riffle[c,c]] (* Harvey P. Dale, Mar 25 2018 *)
    Table[Length[Select[Subsets[Range[n]],!MemberQ[Total/@Tuples[#,2],n]&]],{n,0,10}] (* Gus Wiseman, Oct 18 2023 *)
  • PARI
    A117855(n)=2*3^((n-1)\2) \\ - M. F. Hasler, May 05 2013
    
  • Python
    def A117855(n): return 3**(n-1>>1)<<1 # Chai Wah Wu, Oct 28 2024

Formula

a(n) = 2*3^floor((n-1)/2).
a(n) = 2*A108411(n-1).
From Colin Barker, Feb 15 2013: (Start)
a(n) = 3*a(n-2).
G.f.: -2*x*(x+1)/(3*x^2-1). (End)

Extensions

More terms from Colin Barker, Feb 15 2013

A070199 Number of palindromes of length <= n.

Original entry on oeis.org

10, 19, 109, 199, 1099, 1999, 10999, 19999, 109999, 199999, 1099999, 1999999, 10999999, 19999999, 109999999, 199999999, 1099999999, 1999999999, 10999999999, 19999999999, 109999999999, 199999999999, 1099999999999, 1999999999999, 10999999999999, 19999999999999
Offset: 1

Views

Author

Keywords

Crossrefs

Partial sums of A070252.
Cf. A050250.

Programs

  • Mathematica
    LinearRecurrence[{1,10,-10},{10,19,109},30] (* Harvey P. Dale, Mar 18 2016 *)
  • PARI
    Vec(x*(10+9*x-10*x^2)/((1-x)*(1-10*x^2)) + O(x^40)) \\ Colin Barker, Mar 17 2017
    
  • Python
    def A070199(n): return 10**(n>>1)*(11 if n&1 else 2)-1 # Chai Wah Wu, Jul 30 2025

Formula

From Colin Barker, Jun 30 2012: (Start)
a(n) = a(n-1) + 10*a(n-2) - 10*a(n-3).
G.f.: x*(10 + 9*x - 10*x^2)/((1 - x)*(1 - 10*x^2)). (End)
a(n) = (-2*sqrt(10)+10^(n/2)*(11+2*sqrt(10)+(-1)^n*(-11+2*sqrt(10))))/(2*sqrt(10)). - Harvey P. Dale, Mar 18 2016
From Colin Barker, Mar 17 2017: (Start)
a(n) = 2^(n/2 + 1)*5^(n/2) - 1 for n even.
a(n) = 11*10^((n-1)/2) - 1 for n odd. (End)
a(n) = A050250(n) + 1. - Andrew Howroyd, Oct 28 2020
E.g.f.: 2*cosh(sqrt(10)*x) - cosh(x) - 1 - sinh(x) + 11*sinh(sqrt(10)*x)/sqrt(10). - Stefano Spezia, Jul 01 2023

A368618 a(n) is the n-digit numerator of the fraction h/k with h and k coprime palindrome positive integers at which abs(h/k-e) is minimal.

Original entry on oeis.org

3, 11, 878, 2552, 38983, 167761, 4407044, 24988942, 882646288, 1385885831, 83034443038, 161356653161, 9051164611509, 24911822811942
Offset: 1

Views

Author

Stefano Spezia, Jan 01 2024

Keywords

Comments

a(3) = 878 corresponds to the numerator of A368617.

Examples

			  n              fraction    approximated value
  -   -------------------    ------------------
  1                   3/1    3
  2                  11/4    2.75
  3               878/323    2.7182662538699...
  4              2552/939    2.7177848775292...
  5           38983/14341    2.7182902168607...
  6          167761/61716    2.7182740294251...
  7       4407044/1621261    2.7182816338640...
  8      24988942/9192919    2.7182815382143...
  9   882646288/324707423    2.7182818299783...
  ...
		

Crossrefs

Cf. A001113, A002113, A070252, A368617, A368619 (denominator), A368658.
Cf. A364844 (similar for Pi), A368620, A368621.

Programs

  • Mathematica
    a[1]=3; a[n_]:=Module[{minim = Infinity}, h = Select[Range[10^(n - 1), 10^n - 1], PalindromeQ]; lh = Length[h]; For[i = 1, i <= lh, i++, k = Select[Range[Floor[Part[h, i]/E], Ceiling[Part[h, i]/E]], PalindromeQ]; lk = Length[k]; For[j = 1, j <= lk, j++, If[(dist = Abs[Part[h, i]/Part[k, j] - E]) < minim && GCD[Part[h, i], Part[k, j]] == 1, minim = dist; hmin = Part[h, i]]]]; hmin]; Array[a,9]
  • PARI
    \\ See PARI program in Links

Extensions

a(10)-a(14) from David A. Corneth, Jan 03 2024

A225367 Number of palindromes of length n in base 3 (A118594).

Original entry on oeis.org

3, 2, 6, 6, 18, 18, 54, 54, 162, 162, 486, 486, 1458, 1458, 4374, 4374, 13122, 13122, 39366, 39366, 118098, 118098, 354294, 354294, 1062882, 1062882, 3188646, 3188646, 9565938, 9565938, 28697814, 28697814, 86093442, 86093442, 258280326, 258280326, 774840978
Offset: 1

Views

Author

M. F. Hasler, May 05 2013

Keywords

Comments

Also: The number of n-digit terms in A006072. See there for further comments.
A palindrome of length L=2k-1 or of length L=2k is determined by the first k digits, which then determine the last k digits by symmetry. Since the first digit cannot be 0 (unless L=1), there are 2*3^(k-1) possibilities for L>1.
Except for the initial term, this is identical to A117855, which counts only nonzero palindromes.

Examples

			The a(1)=3 palindromes of length 1 are: 0, 1 and 2.
The a(2)=2 palindromes of length 2 are: 11 and 22.
		

Crossrefs

Cf. A050683 and A070252 for base 10 analogs.

Programs

  • Magma
    [n eq 1 select 3 else 2*3^Floor((n-1)/2): n in [1..40]]; // Bruno Berselli, May 06 2013
    
  • Magma
    I:=[3,2,6]; [n le 3 select I[n] else 3*Self(n-2): n in [1..40]]; // Vincenzo Librandi, May 31 2017
    
  • Mathematica
    Join[{3}, LinearRecurrence[{0, 3}, {2, 6}, 40]] (* Vincenzo Librandi, May 31 2017 *)
  • PARI
    A225367(n)=2*3^((n-1)\2)+!n
    
  • Python
    def A225367(n): return 3 if n==1 else 3**(n-1>>1)<<1 # Chai Wah Wu, Jul 30 2025

Formula

a(n) = 2*3^floor((n-1)/2) + [n=1].
a(n) = 3*a(n-2) for n>3.
G.f.: x*(3*x^2-2*x-3)/(3*x^2-1).
a(n) = (6-(1+(-1)^n)*(3-sqrt(3)))*sqrt(3)^(n-3) for n>1, a(1)=3. [Bruno Berselli, May 06 2013]

A368619 a(n) is the n-digit denominator of the fraction h/k with h and k coprime palindrome positive integers at which abs(h/k-e) is minimal.

Original entry on oeis.org

1, 4, 323, 939, 14341, 61716, 1621261, 9192919, 324707423, 509838905, 30546664503, 59359795395, 3329737379233, 9164547454619
Offset: 1

Views

Author

Stefano Spezia, Jan 01 2024

Keywords

Comments

a(3) = 323 corresponds to the denominator of A368617.

Examples

			  n              fraction    approximated value
  -   -------------------    ------------------
  1                   3/1    3
  2                  11/4    2.75
  3               878/323    2.7182662538699...
  4              2552/939    2.7177848775292...
  5           38983/14341    2.7182902168607...
  6          167761/61716    2.7182740294251...
  7       4407044/1621261    2.7182816338640...
  8      24988942/9192919    2.7182815382143...
  9   882646288/324707423    2.7182818299783...
  ...
		

Crossrefs

Cf. A364845 (similar for Pi), A368620, A368621.

Programs

  • Mathematica
    a[1]=1; a[n_]:=Module[{minim = Infinity}, h = Select[Range[10^(n - 1), 10^n - 1], PalindromeQ]; lh = Length[h]; For[i = 1, i <= lh, i++, k = Select[Range[Floor[Part[h, i]/E], Ceiling[Part[h, i]/E]], PalindromeQ]; lk = Length[k]; For[j = 1, j <= lk, j++, If[(dist = Abs[Part[h, i]/Part[k, j] - E]) < minim && GCD[Part[h, i], Part[k, j]] == 1, minim = dist; kmin = Part[k, j]]]]; kmin]; Array[a,9]
  • PARI
    \\ See PARI program in Links

Extensions

a(10)-a(14) from David A. Corneth, Jan 03 2024

A364844 a(n) is the n-digit numerator of the fraction h/k with h and k coprime palindrome positive integers at which abs(h/k-Pi) is minimal.

Original entry on oeis.org

3, 22, 474, 1551, 36163, 292292, 7327237, 31311313
Offset: 1

Views

Author

Stefano Spezia, Aug 10 2023

Keywords

Comments

a(2) = 22 corresponds to the numerator of A068028.

Examples

			  n              fraction    approximated value
  -   -------------------    ------------------
  1                     3    3
  2                  22/7    3.1428571428571...
  3               474/151    3.1390728476821...
  4              1551/494    3.1396761133603...
  5           36163/11511    3.1416036834332...
  6          292292/93039    3.1416072829673...
  7       7327237/2332332    3.1415926206046...
  8      31311313/9966699    3.1415931192464...
  ...
		

Crossrefs

Programs

  • Mathematica
    nmax = 8; a = {3}; hmin = kmin = 0; For[n = 2, n <= nmax, n++, minim = Infinity; h = Select[Range[10^(n - 1), 10^n - 1], PalindromeQ]; k = Select[Range[10^(n - 2), 10^n - 1], PalindromeQ]; lh = Length[h]; lk = Length[k]; For[i = 1, i <= lh, i++, For[j = 1, j <= lk, j++, If[(dist = Abs[Part[h, i]/Part[k, j] - Pi]) < minim && GCD[Part[h, i], Part[k, j]] == 1, minim = dist; hmin = Part[h, i]]]]; AppendTo[a, hmin]]; a

A364845 a(n) is the denominator of the fraction h/k with h and k coprime palindrome positive integers at which abs(h/k-Pi) is minimal, with the numerator h of n digits.

Original entry on oeis.org

1, 7, 151, 494, 11511, 93039, 2332332, 9966699
Offset: 1

Views

Author

Stefano Spezia, Aug 10 2023

Keywords

Comments

a(2) = 7 corresponds to the denominator of A068028.

Examples

			  n              fraction    approximated value
  -   -------------------    ------------------
  1                     3    3
  2                  22/7    3.1428571428571...
  3               474/151    3.1390728476821...
  4              1551/494    3.1396761133603...
  5           36163/11511    3.1416036834332...
  6          292292/93039    3.1416072829673...
  7       7327237/2332332    3.1415926206046...
  8      31311313/9966699    3.1415931192464...
  ...
		

Crossrefs

Programs

  • Mathematica
    nmax = 8; a = {1}; hmin = kmin = 0; For[n = 2, n <= nmax, n++, minim = Infinity; h = Select[Range[10^(n - 1), 10^n - 1], PalindromeQ]; k = Select[Range[10^(n - 2), 10^n - 1], PalindromeQ]; lh = Length[h]; lk = Length[k];  For[i = 1, i <= lh, i++, For[j = 1, j <= lk, j++, If[(dist = Abs[Part[h, i]/Part[k, j] - Pi]) < minim && GCD[Part[h, i], Part[k, j]] == 1, minim = dist; kmin = Part[k, j]]]]; AppendTo[a, kmin]]; a

A218035 Number of n-digit palindromes with squares that are also palindromes.

Original entry on oeis.org

4, 2, 5, 3, 8, 5, 13, 9, 22, 16, 37, 27, 60, 43, 93, 65, 138, 94, 197, 131, 272, 177, 365, 233, 478, 300, 613, 379, 772, 471, 957, 577, 1170, 698, 1413, 835, 1688, 989, 1997, 1161, 2342, 1352, 2725, 1563, 3148, 1795, 3613, 2049, 4122, 2326, 4677, 2627, 5280, 2953
Offset: 1

Views

Author

David Zvirbulis, Oct 19 2012

Keywords

Comments

Number of n-digit terms in A057135.
From Chai Wah Wu, Apr 03 2021: (Start)
The conjectures in the formula section are true.
Theorem: a(n) = (n^3-6*n^2+32*n+48)/48 if n is even.
a(n) = (n^3-9*n^2+59*n-3)/24 if n > 1 is odd.
Proof: For n < 9, this is true by inspection.
The set of palindromes whose square are palindromic are the numbers whose squares of the digits sums to less than 10 (see A057135). For n >= 9, the nonzero digits are from one of the following 12 sets:
(1, 1, 1, 1, 1, 1, 1, 1), (1, 2, 2), (1, 1, 1, 1), (1, 1, 2), (1, 1, 1, 1, 1, 1, 1), (1, 1, 1, 1, 1, 1, 1, 1, 1), (2, 2), (1, 1, 1), (1, 1, 1, 1, 1), (1, 1), (1, 1, 1, 1, 2), (1, 1, 1, 1, 1, 1)
For odd n >= 9:
(1, 1, 1, 1, 1, 1, 1, 1): number of palindromes with 8 1's and n-8 0's is C((n-3)/2,3) = (n-3)(n-5)(n-7)/48. This is because all palindromes must start and end with a nonzero digit and the middle digit is necessarily 0, so only the (n-3) remaining digits are permuted with 6 1's and (n-9) 0's. By symmetry of the palindromes the number of combinations is C((n-3)/2,3).
(1, 2, 2): 1 palindrome of the form 20..010..2.
(1, 1, 1, 1): number of palindromes with 4 1's and n-4 0's is C((n-3)/2,1) = (n-3)/2.
(1, 1, 2): 1 palindrome of the form 10..020..1.
(1, 1, 1): 1 palindrome of the form 10..010..1.
(1, 1, 1, 1, 1): number of palindromes with 5 1's and n-5 0's is C((n-3)/2,1) = (n-3)/2.
(1, 1, 1, 1, 2): C((n-3)/2,1) = (n-3)/2.
(1, 1, 1, 1, 1, 1, 1): C((n-3)/2,2).
(1, 1, 1, 1, 1, 1, 1, 1, 1): C((n-3)/2,3).
(2,2): 1 palindrome of the form 200...002.
(1,1): 1 palindrome of the form 100...001.
(1,1,1,1,1,1): number of palindromes with 6 1's and n-6 0's is C((n-3)/2,2) = (n-3)(n-5)/8.
Thus A218035(n) = 2*(n-3)(n-5)(n-7)/48 +2*(n-3)(n-5)/8 +3*(n-3)/2 + 5 = (n^3-9n^2+59n-3)/24.
For even n >= 9:
(1, 2, 2), (1, 1, 2), (1, 1, 1), (1, 1, 1, 1, 1), (1, 1, 1, 1, 2), (1, 1, 1, 1, 1, 1, 1), (1, 1, 1, 1, 1, 1, 1, 1, 1): no palindromes are possible.
(1, 1, 1, 1, 1, 1, 1, 1): number of palindromes 8 1's and n-8 0's = C((n-2)/2,3) = (n-2)(n-4)(n-6)/48.
(1, 1, 1, 1): number of palindromes with 4 1's and n-4 0's is C((n-2)/2,1) = (n-2)/2.
(2,2): 1 palindrome of the form 200...002.
(1,1): 1 palindrome of the form 100...001.
(1,1,1,1,1,1): number of palindromes with 6 1's and n-6 0's is C((n-2)/2,2) = (n-2)(n-4)/8.
Thus A218035(n) = (n-2)(n-4)(n-6)/48 + (n-2)(n-4)/8 + (n-2)/2 +2 = (n^3-6n^2+32n+48)/48. QED
(End)

Examples

			For n=4, the solutions are:
1001, 1001^2 = 1002001,
1111, 1111^2 = 1234321,
2002, 2002^2 = 4008004.
		

Crossrefs

Programs

  • Python
    from itertools import product
    def ispal(n): s = str(n); return s == s[::-1]
    def pals(n):
      midrange = [[""], [str(i) for i in range(10)]]
      for p in product("0123456789", repeat=n//2):
        left = "".join(p)
        if len(left) and left[0] == '0': continue
        for middle in midrange[n%2]: yield left+middle+left[::-1]
    def a(n): return sum(ispal(int(strpal)**2) for strpal in pals(n))
    print([a(n) for n in range(1, 13)]) # Michael S. Branicky, Apr 02 2021
    
  • Python
    def A218035(n): return 4 if n == 1 else (n**3-9*n**2+59*n-3)//24 if n % 2 else (n**3-6*n**2+32*n+48)//48 # Chai Wah Wu, Apr 03 2021

Formula

Conjecture: a(n) = n^3/48 - n^2/8 + 2n/3 + 1 if n even, see A011826.
Conjecture: a(n) = n^3/24 - 3n^2/8 + 59n/24 - 1/8 if n odd, n > 1.
From Chai Wah Wu, Apr 03 2021: (Start)
a(n) = 4*a(n-2) - 6*a(n-4) + 4*a(n-6) - a(n-8) for n > 9.
G.f.: x*(2*x^8 - x^7 - 5*x^6 + 5*x^5 + 12*x^4 - 5*x^3 - 11*x^2 + 2*x + 4)/((x - 1)^4*(x + 1)^4). (End)

Extensions

a(19)-a(20) from Michael S. Branicky, Apr 02 2021
More terms from Chai Wah Wu, Apr 03 2021

A217789 Least difference between 2 palindromic numbers of length n.

Original entry on oeis.org

1, 11, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11
Offset: 1

Views

Author

Michel Marcus, Mar 25 2013

Keywords

Comments

In his video, Fields medallist Villani asks about the number of palindromes of length n (cf. A050683 and A070252), and the minimal difference among any two of these (this sequence). Except for the 1 and 3-digits case (where e.g. 111-101=10), the minimal difference of 11 appears as 20...02 - 19...91 and similar patterns (1st and last digits increased by 1,...,7). - M. F. Hasler, Mar 25 2013
Also, continued fraction expansion of (2695-5*sqrt(5))/2462. [Bruno Berselli, Mar 25 2013]

Examples

			a(1)=1 for instance 8-7.
a(2)=11 for instance 22-11.
a(3)=10 for instance 111-101.
a(n)=11 for n >= 4, for instance 2002-1991, resp. generalization to n digits (cf. comment).
		

Crossrefs

Programs

Formula

G.f.: x*(1+10*x-x^2+x^3)/(1-x). [Bruno Berselli, Mar 25 2013]
Showing 1-10 of 11 results. Next