|
|
A140358
|
|
Smallest nonnegative integer k such that n = +-1+-2+-...+-k for some choice of +'s and -'s.
|
|
3
|
|
|
0, 1, 3, 2, 3, 5, 3, 5, 4, 5, 4, 5, 7, 5, 7, 5, 7, 6, 7, 6, 7, 6, 7, 9, 7, 9, 7, 9, 7, 9, 8, 9, 8, 9, 8, 9, 8, 9, 11, 9, 11, 9, 11, 9, 11, 9, 11, 10, 11, 10, 11, 10, 11, 10, 11, 10, 11, 13, 11, 13, 11, 13, 11, 13, 11, 13, 11, 13, 12, 13, 12, 13, 12, 13, 12, 13, 12, 13, 12, 13, 15, 13, 15, 13
(list;
graph;
refs;
listen;
history;
text;
internal format)
|
|
|
OFFSET
|
0,3
|
|
LINKS
|
|
|
FORMULA
|
Conjecture when n is greater than 0. Choose k so that t(k)<=n<t(k+1) where t(n) is the n-th triangular number t(n)=n(n+1)/2. If n=t(k), a(n)=k, otherwise if k is odd then a(n)=k+2 if n-t(k) is odd, a(n)=k+1 if n-t(k) is even, else if k is even than a(n)=k+1 if n-t(k) is odd, a(n)=k+3 if n-t(k) is even. (This has been verified for n up to 100.)
Let k be the least integer such that t(k) >= n. If t(k) and n have the same parity then a(n) = k. Otherwise a(n) is equal to the least odd integer greater than k. - Rishi Advani, Jan 24 2021
|
|
EXAMPLE
|
Illustration of initial terms:
0 = 0 (empty sum).
1 = 1.
2 = 1 - 2 + 3.
3 = 1 + 2.
4 = -1 + 2 + 3.
5 = 1 + 2 + 3 + 4 - 5.
6 = 1 + 2 + 3.
7 = 1 + 2 + 3 - 4 + 5.
8 = -1 + 2 + 3 + 4.
9 = 1 + 2 - 3 + 4 + 5.
10 = 1 + 2 + 3 + 4.
... (End)
|
|
MAPLE
|
b:= proc(n, i) option remember;
(n=0 and i=0) or n<=i*(i+1)/2 and (b(abs(n-i), i-1) or b(n+i, i-1))
end:
a:= proc(n) local k;
for k from 0 while not b(n, k) do od; k
end:
|
|
MATHEMATICA
|
b[n_, i_] := b[n, i] = (n==0 && i==0) || Abs[n] <= i(i+1)/2 && (b[n-i, i-1] || b[n+i, i-1]);
a[n_] := Module[{k}, For[k = 0, !b[n, k], k++]; k];
|
|
CROSSREFS
|
|
|
KEYWORD
|
|
|
AUTHOR
|
|
|
EXTENSIONS
|
|
|
STATUS
|
approved
|
|
|
|