login
a(n) = n^2 - a(n-1) - a(n-2), with a(1) = 1 and a(2) = 2.
2

%I #40 Aug 06 2016 16:37:30

%S 1,2,6,8,11,17,21,26,34,40,47,57,65,74,86,96,107,121,133,146,162,176,

%T 191,209,225,242,262,280,299,321,341,362,386,408,431,457,481,506,534,

%U 560,587,617,645,674,706,736,767,801,833,866,902,936,971,1009,1045,1082

%N a(n) = n^2 - a(n-1) - a(n-2), with a(1) = 1 and a(2) = 2.

%C Any three consecutive terms sum up to a perfect square. First 9 terms coincide with A076991.

%C Changing a(1) leaves a(5+3m) constant for m >= 0. Changing a(2) leaves a(4+3m) constant for m >= 0. - _Richard R. Forberg_, Jun 05 2013

%H <a href="/index/Rec#order_05">Index entries for linear recurrences with constant coefficients</a>, signature (2,-1,1,-2,1).

%F a(1)=1, a(2)=2; n>2: a(n)=n^2-a(n-1)-a(n-2).

%F G.f.: x*(1+3*x^2-3*x^3+x^4)/(1+x+x^2)/(1-x)^3. - Maksym Voznyy (voznyy(AT)mail.ru), Jul 27 2009; checked and corrected by _R. J. Mathar_, Sep 16 2009

%F a(n) = floor((n^2+2*n+1)/3) + 1 - (n mod 3). - _Ivan Neretin_, May 25 2015

%F For n>6, a(n)=2*a(n-3)-a(n-6)+6. - _Zak Seidov_, Aug 05 2016

%F a(n) = (3*n^2+6*n+1 +8*A049347(n)+7*A049347(n-1))/9.. - _R. J. Mathar_, Aug 06 2016

%e 1+2+6=3^2, 2+6+8=4^2, 6+8+11=5^2.

%e G.f. = x + 2*x^2 + 6*x^3 + 8*x^4 + 11*x^5 + 17*x^6 + 21*x^7 + 26*x^8 + ...

%p A130205 := proc(n)

%p option remember;

%p if n <= 2 then

%p n;

%p else

%p n^2-procname(n-1)-procname(n-2) ;

%p end if;

%p end proc:

%p seq(A130205(n),n=1..50) ; # _R. J. Mathar_, Aug 06 2016

%t a[1]=1;a[2]=2;a[n_]:=a[n]=n^2-a[n-1]-a[n-2]; Table[a[n],{n,100}]

%t a[ n_] := Quotient[ (n + 1)^2, 3] + 1 - Mod[n, 3]; (* _Michael Somos_, Aug 04 2016 *)

%o (PARI) a(n)=(n^2+2*n+4)\3 - n%3 \\ _Charles R Greathouse IV_, Aug 03 2016

%Y Cf. A076991, A001840.

%K nonn,easy

%O 1,2

%A _Zak Seidov_, May 16 2007