login

Year-end appeal: Please make a donation to the OEIS Foundation to support ongoing development and maintenance of the OEIS. We are now in our 61st year, we have over 378,000 sequences, and we’ve reached 11,000 citations (which often say “discovered thanks to the OEIS”).

Smallest positive integer k such that n = +-1 +-3 +-... +-(2k-1) for some choice of +'s and -'s
2

%I #27 Nov 12 2020 06:32:08

%S 1,2,3,2,5,4,3,4,3,4,5,6,5,4,5,4,5,6,5,6,7,6,5,6,5,6,7,6,7,6,7,8,7,6,

%T 7,6,7,8,7,8,7,8,7,8,9,8,7,8,7,8,9,8,9,8,9,8,9,8,9,10,9,8,9,8,9,10,9,

%U 10,9,10,9,10,9,10,9,10,11,10,9,10,9,10,11,10,11,10,11,10,11,10,11,10,11,10,11,12,11,10,11,10

%N Smallest positive integer k such that n = +-1 +-3 +-... +-(2k-1) for some choice of +'s and -'s

%C Conjecture. Let SO(k) be the sum of the first k odd positive integers. Then a(n)=k if n=SO(k). Otherwise, choose k so that SO(k-1)<n<SO(k). Then if SO(k)-n=4, a(n)=k+2, else if SO(k)-n is odd then a(n)=k+1 else a(n)=k. (This has been verified for n up to 200.)

%H Alois P. Heinz, <a href="/A197702/b197702.txt">Table of n, a(n) for n = 1..10000</a>

%e The sum of 3 terms 1 - 3 + 5 gives 3, but none of the 2-term sums 1+3, 1-3, -1+3, -1-3 gives 3, so a(3)=3.

%p b:= proc(n, i) option remember; (n=0 and i=0) or

%p abs(n)<=i^2 and (b(n-2*i+1, i-1) or b(n+2*i-1, i-1))

%p end:

%p a:= proc(n) local k;

%p for k from floor(sqrt(n)) while not b(n, k) do od; k

%p end:

%p seq(a(n), n=1..100); # _Alois P. Heinz_, Oct 19 2011

%t b[n_, i_] := b[n, i] = (n==0 && i==0) || Abs[n] <= i^2 && (b[n-2i+1, i-1] || b[n+2i-1, i-1]);

%t a[n_] := Module[{k}, For[k = Floor[Sqrt[n]], !b[n, k], k++]; k];

%t Array[a, 100] (* _Jean-François Alcover_, Nov 12 2020, after _Alois P. Heinz_ *)

%Y Cf. A140358.

%K nonn

%O 1,2

%A _John W. Layman_, Oct 18 2011