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.

This page as a plain text file.
%I A334535 #70 Jun 30 2020 21:15:13
%S A334535 1,2,3,5,8,19,27,24,45,69,72,51,27,24,45,69,72,51,27,30,57,81,78,51,
%T A334535 75,126,153,333,486,459,891,1350,1377,945,486,459,891,1350,1377,945,
%U A334535 486,459,891,1350,1377,945,486,459,891,1350,1377,2781,4158,4131,2727,1350
%N 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.
%C A334535 The sequence is piecewise-periodic.
%H A334535 Smirnov Vladimir, <a href="/A334535/b334535.txt">Table of n, a(n) for n = 1..3000</a>
%F A334535 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...
%e A334535 For n = 6, a(n-i) = a(6-2) = a(4) = 5; a(6) = 2*a(5)+a(5)-a(4) = 19.
%e A334535 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.
%e A334535 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.
%e A334535 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.
%p A334535 a[1] := 1:
%p A334535 a[2] := 2:
%p A334535 for n from 3 to 100 do
%p A334535   i := 2;
%p A334535   while a[n-i] >= n do i := i+1;
%p A334535   end do:
%p A334535   a[n] := 2*a[a[n-i]]+a[n-1]-a[n-2]
%p A334535 end do:
%p A334535 seq(a[n], n=1..100);
%t A334535 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}]
%o A334535 (C) int main() {
%o A334535 int a[100];
%o A334535 a[1]=1;
%o A334535 a[2]=2;
%o A334535 printf("%d\n", 1);
%o A334535 printf("%d\n", 2);
%o A334535 for (int n=3; n<=99; n++)
%o A334535 {int i=2;
%o A334535 while (a[n-i]>=n) {i++;}
%o A334535 a[n]=2*a[a[n-i]]+a[n-1]-a[n-2];
%o A334535 printf("%d\n", a[n]);}
%o A334535 return 0; }
%o A334535 (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
%o A334535 (Python)
%o A334535 from functools import lru_cache
%o A334535 @lru_cache(maxsize=None)
%o A334535 def A334535(n):
%o A334535     if n <= 2:
%o A334535         return n
%o A334535     i, a, b = 2, A334535(n-1), A334535(n-2)
%o A334535     q = b
%o A334535     while q >= n:
%o A334535         i += 1
%o A334535         q = A334535(n-i)
%o A334535     return 2*A334535(q)+a-b # _Chai Wah Wu_, Jun 30 2020
%Y A334535 Cf. A030118.
%K A334535 nonn
%O A334535 1,2
%A A334535 _Smirnov Vladimir_, May 05 2020