|
|
A270841
|
|
a(1) = 5; a(n) is the sum of |a(m) - m| for m < n.
|
|
2
|
|
|
5, 4, 6, 9, 14, 23, 40, 73, 138, 267, 524, 1037, 2062, 4111, 8208, 16401, 32786, 65555, 131092, 262165, 524310, 1048599, 2097176, 4194329, 8388634, 16777243, 33554460, 67108893, 134217758, 268435487, 536870944, 1073741857, 2147483682, 4294967331, 8589934628
(list;
graph;
refs;
listen;
history;
text;
internal format)
|
|
|
OFFSET
|
1,1
|
|
LINKS
|
|
|
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
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
(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
|
|
CROSSREFS
|
|
|
KEYWORD
|
easy,nonn
|
|
AUTHOR
|
|
|
EXTENSIONS
|
|
|
STATUS
|
approved
|
|
|
|