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”).

Distance from 2^n to the nearest triangular number.
3

%I #22 Feb 28 2014 11:12:26

%S 0,1,1,2,1,4,2,8,3,16,11,32,1,64,87,128,167,256,306,512,500,1024,552,

%T 2048,688,4096,3041,8192,579,16384,20854,32768,37075,65536,55618,

%U 131072,37108,262144,222296,524288,147729,1048576,891994,2097152,602155,4194304,3523022

%N Distance from 2^n to the nearest triangular number.

%F a(2*k+1) = 2^k.

%F Specifically, both the nearest triangular number below: A006516(n) = A000217((2^n)-1) = 2^(2n-1) - 2^(n-1) and the nearest triangular number above: A007582(n) = A000217(2^n) = 2^(2n-1) + 2^(n-1) are at the same distance from 2^(2n-1). - _Antti Karttunen_, Feb 26 2014

%e Triangular number nearest to 2^8=256 is 253, so a(8)=256-253=3.

%t a[n_] := Module[{k, k0}, k0 = k /. FindRoot[2^n == k*(k+1)/2, {k, 2^(n/2)}, WorkingPrecision -> 20] // Round; Abs[2^n-k0*(k0+1)/2]]; Table[a[n], {n, 0, 46}] (* _Jean-François Alcover_, Feb 27 2014 *)

%Y Bisections: a(2n) = abs(A238455(n)), a(2n+1) = A000079(n).

%Y Cf. A000217, A006516, A007582.

%K nonn,easy

%O 0,4

%A _Alex Ratushnyak_, Feb 23 2014