login
The OEIS is supported by the many generous donors to the OEIS Foundation.

 

Logo
Hints
(Greetings from The On-Line Encyclopedia of Integer Sequences!)
A008935 If 2n = Sum 2^e(k) then a(n) = Sum e(k)^2. 5
1, 4, 5, 9, 10, 13, 14, 16, 17, 20, 21, 25, 26, 29, 30, 25, 26, 29, 30, 34, 35, 38, 39, 41, 42, 45, 46, 50, 51, 54, 55, 36, 37, 40, 41, 45, 46, 49, 50, 52, 53, 56, 57, 61, 62, 65, 66, 61, 62, 65, 66, 70, 71, 74, 75, 77, 78, 81, 82, 86, 87, 90, 91, 49, 50, 53, 54, 58, 59, 62 (list; graph; refs; listen; history; text; internal format)
OFFSET
1,2
LINKS
FORMULA
G.f.: 1/(1-x) * Sum_{k>=0} (k+1)^2*x^2^k/(1+x^2^k). - Ralf Stephan, Jun 23 2003
EXAMPLE
To get a(5), we write 10 = 2 + 8 = 2^1 + 2^3 so a(5) = 1^2 + 3^2 = 10.
MAPLE
a:= n-> (l-> add(l[i]*i^2, i=1..nops(l)))(convert(n, base, 2)):
seq(a(n), n=1..80); # Alois P. Heinz, Nov 20 2019
MATHEMATICA
a[n_] := Total[Flatten[Position[Reverse[IntegerDigits[n, 2]], 1]]^2]; Table[a[n], {n, 1, 70}] (* Jean-François Alcover Mar 21 2011 *)
PROG
(C)
#include <stdio.h>
#include <stdlib.h>
#define USAGE "Usage: 'A008935 num'\n where num is the index of the desired ending value in the sequence.\n"
#define MAX 1023
#define SHIFT_MAX 9
int main(int argc, char *argv[]) { unsigned short mask, i, j, end; unsigned long sum; if (argc < 2) { fprintf(stderr, USAGE); return EXIT_FAILURE; } end = atoi(argv[1]); end = (end >= MAX) ? MAX : end;
fprintf(stdout, "Values: "); for (i = 1; i <= end; i++) { sum = 0; mask = 1; for (j = 0; j < SHIFT_MAX; j++, mask *= 2) if (i & mask) sum += (j+1) * (j+1); fprintf(stdout, "%ld", sum); if (i < end) fprintf(stdout, ", "); } fprintf(stdout, "\n"); return EXIT_SUCCESS; }
(Haskell)
a008935 = f 1 where
f k x | x == 0 = 0
| r == 0 = f (k+1) x'
| otherwise = k^2 + f (k+1) x' where (x', r) = divMod x 2
-- Reinhard Zumkeller, Jul 05 2011
CROSSREFS
Gives A003995 if sorted and duplicates removed.
Sequence in context: A109825 A327175 A193259 * A003995 A064473 A287962
KEYWORD
nonn,nice,easy
AUTHOR
EXTENSIONS
Corrected and extended by Larry Reeves (larryr(AT)acm.org), Mar 22 2000
STATUS
approved

Lookup | Welcome | Wiki | Register | Music | Plot 2 | Demos | Index | Browse | More | WebCam
Contribute new seq. or comment | Format | Style Sheet | Transforms | Superseeker | Recents
The OEIS Community | Maintained by The OEIS Foundation Inc.

License Agreements, Terms of Use, Privacy Policy. .

Last modified April 25 01:35 EDT 2024. Contains 371964 sequences. (Running on oeis4.)