OFFSET
1,1
COMMENTS
From R. J. Mathar, Nov 12 2011: (Start)
The function bin_prime_sum of an argument n is a sum of three numbers. Let s = A000523(n) be the exponent of the largest power of 2 less than or equal to n and prime=A000040. Then the three terms are:
i) (-1)^(n+1);
ii) sum_{i=1..s} prime(i) * (1 + (-1)^[n/2^i] ); where [..] is the floor bracket;
iii) 1 (if n=1), otherwise prime(s) (if s even) or 0 (if s odd). (End)
MAPLE
with(numtheory); bin_prime_sum := proc(n) local i, s; s := floor_log_2(n); RETURN(((-1)^(n+1)) + add( (((-1)^(floor(n/(2^i))+1))*ithprime(i)), i=1..s) + (`if`((1 = n), 1, ((`mod`((s+1), 2))*ithprime(s)))) ); end;
MATHEMATICA
a[n_] := With[{s = Floor[Log[2, n]]}, (-1)^(n+1) + Sum[(-1)^(Floor[n/2^i] + 1)*Prime[i], {i, 1, s}] + If[1 == n, 1, Mod[s+1, 2]*Prime[s]]]; Array[a, 105] (* Jean-François Alcover, Mar 07 2016, adapted from Maple *)
CROSSREFS
KEYWORD
sign
AUTHOR
Antti Karttunen, Feb 05 2001
STATUS
approved