OFFSET
1,1
LINKS
Colin Barker, Table of n, a(n) for n = 1..1000
Index entries for linear recurrences with constant coefficients, signature (4,-5,2).
FORMULA
For n > 2, a(n) = a(n - 2) + |a(n - 1) - (n - 1)|
For n > 2, a(n) = 2^(n - 2) + n + 1. - Peter Kagey, Mar 25 2016
From Colin Barker, Mar 28 2016: (Start)
a(n) = 4*a(n-1)-5*a(n-2)+2*a(n-3) for n>4.
G.f.: x*(5-16*x+15*x^2-5*x^3) / ((1-x)^2*(1-2*x)).
(End)
EXAMPLE
a(1) = 5;
a(2) = 4 because |a(1) - 1| = 4
a(3) = 6 because |a(2) - 2| + |a(1) - 1| = 6
a(4) = 9 because |a(3) - 3| + |a(2) - 2| + |a(1) - 1| = 9
(...)
MATHEMATICA
a[1] := 5
a[n_]:= 2^(n - 2) + n + 1 (* Peter Kagey, Mar 25 2016 *)
PROG
(Java)
public static int[] a(int n) {
int[] terms = new int[n];
terms[0] = 0;
terms[1] = 5;
for (int i = 2; i < n; i++) {
int count = 0;
for (int j = 0; j < i; j++) {
count = count + abs(j - terms[j]);
}
terms[i] = count;
}
return terms;
}
(Ruby)
def a270841(n); n == 1 ? 5 : 2**(n - 2) + n + 1 end
# Peter Kagey, Mar 25 2016
(PARI) Vec(x*(5-16*x+15*x^2-5*x^3)/((1-x)^2*(1-2*x)) + O(x^50)) \\ Colin Barker, Mar 28 2016
(PARI) a(n)=if(n>1, 2^(n-2)+n+1, 5) \\ Charles R Greathouse IV, Mar 28 2016
CROSSREFS
KEYWORD
easy,nonn
AUTHOR
Alec Jones, Mar 23 2016
EXTENSIONS
More terms from Colin Barker, Mar 28 2016
STATUS
approved