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.

A334535 a(1) = 1, a(2) = 2, and for n > 2, a(n) = 2*a(a(n-i))+a(n-1)-a(n-2) where i >= 2 is the smallest number that satisfies a(n-i) < n.

Original entry on oeis.org

1, 2, 3, 5, 8, 19, 27, 24, 45, 69, 72, 51, 27, 24, 45, 69, 72, 51, 27, 30, 57, 81, 78, 51, 75, 126, 153, 333, 486, 459, 891, 1350, 1377, 945, 486, 459, 891, 1350, 1377, 945, 486, 459, 891, 1350, 1377, 945, 486, 459, 891, 1350, 1377, 2781, 4158, 4131, 2727, 1350
Offset: 1

Views

Author

Smirnov Vladimir, May 05 2020

Keywords

Comments

The sequence is piecewise-periodic.

Examples

			For n = 6, a(n-i) = a(6-2) = a(4) = 5; a(6) = 2*a(5)+a(5)-a(4) = 19.
For n = 7, a(n-i) = a(7-2) = a(5) = 8; but a(n-i)>n, then a(n-i) = a(7-3) = a(4) = 5; a(7) = 2*a(5)+a(6)-a(5) = 27.
For n = 9, a(n-i) = a(9-2) = a(7) = 27; but a(n-i)>n, then a(n-i) = a(9-3) = a(6) = 19; but a(n-i)>n, then a(n-i) = a(9-4) = a(5) = 8; a(9) = 2*a(8)+a(8)-a(7) = 45.
Simplified calculation option for n = 31, a(n-i) = a(31-2) = a(29) = 486; but a(n-i)> n, visually find in the sequence such a(n) that is located closest to the end of the sequence and less than n: this is a(20) = 30, then a(n-i) = 30; a(31) = 2 * a(30) + a(30)- a(29) = 891.
		

Crossrefs

Cf. A030118.

Programs

  • C
    int main() {
    int a[100];
    a[1]=1;
    a[2]=2;
    printf("%d\n", 1);
    printf("%d\n", 2);
    for (int n=3; n<=99; n++)
    {int i=2;
    while (a[n-i]>=n) {i++;}
    a[n]=2*a[a[n-i]]+a[n-1]-a[n-2];
    printf("%d\n", a[n]);}
    return 0; }
    
  • Maple
    a[1] := 1:
    a[2] := 2:
    for n from 3 to 100 do
      i := 2;
      while a[n-i] >= n do i := i+1;
      end do:
      a[n] := 2*a[a[n-i]]+a[n-1]-a[n-2]
    end do:
    seq(a[n], n=1..100);
  • Mathematica
    a[1]=1;a[2]=2;For[n=3,n<=100,n++,i=2;While[a[n-i]>=n,i++];a[n]= 2*a[a[n-i]]+a[n-1]-a[n-2]];Table[a[n],{n,1,100}]
  • PARI
    lista(nn) = {my(va = vector(nn)); va[1] = 1; va[2] = 2; for (n=3, nn, my(i = 2); while(va[n-i] >= n, i++); va[n] = 2*va[va[n-i]]+va[n-1]-va[n-2];); va;} \\ Michel Marcus, May 09 2020
    
  • Python
    from functools import lru_cache
    @lru_cache(maxsize=None)
    def A334535(n):
        if n <= 2:
            return n
        i, a, b = 2, A334535(n-1), A334535(n-2)
        q = b
        while q >= n:
            i += 1
            q = A334535(n-i)
        return 2*A334535(q)+a-b # Chai Wah Wu, Jun 30 2020

Formula

a(n) = 2*a(a(n-i))+a(n-1)-a(n-2) where i = 2, unless a(n-i) >= n, in which case i = 3,4,5,6...