This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.
%I A008935 #38 Dec 27 2024 14:56:01 %S A008935 1,4,5,9,10,13,14,16,17,20,21,25,26,29,30,25,26,29,30,34,35,38,39,41, %T A008935 42,45,46,50,51,54,55,36,37,40,41,45,46,49,50,52,53,56,57,61,62,65,66, %U A008935 61,62,65,66,70,71,74,75,77,78,81,82,86,87,90,91,49,50,53,54,58,59,62 %N A008935 If 2n = Sum 2^e(k) then a(n) = Sum e(k)^2. %H A008935 T. D. Noe, <a href="/A008935/b008935.txt">Table of n, a(n) for n=1..1023</a> %F A008935 G.f.: 1/(1-x) * Sum_{k>=0} (k+1)^2*x^2^k/(1+x^2^k). - _Ralf Stephan_, Jun 23 2003 %e A008935 To get a(5), we write 10 = 2 + 8 = 2^1 + 2^3 so a(5) = 1^2 + 3^2 = 10. %p A008935 a:= n-> (l-> add(l[i]*i^2, i=1..nops(l)))(convert(n, base, 2)): %p A008935 seq(a(n), n=1..80); # _Alois P. Heinz_, Nov 20 2019 %t A008935 a[n_] := Total[Flatten[Position[Reverse[IntegerDigits[n, 2]], 1]]^2]; Table[a[n],{n,1,70}] (* Jean-François Alcover Mar 21 2011 *) %o A008935 (C) %o A008935 #include <stdio.h> %o A008935 #include <stdlib.h> %o A008935 #define USAGE "Usage: 'A008935 num'\n where num is the index of the desired ending value in the sequence.\n" %o A008935 #define MAX 1023 %o A008935 #define SHIFT_MAX 9 %o A008935 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; %o A008935 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; } %o A008935 (Haskell) %o A008935 a008935 = f 1 where %o A008935 f k x | x == 0 = 0 %o A008935 | r == 0 = f (k+1) x' %o A008935 | otherwise = k^2 + f (k+1) x' where (x',r) = divMod x 2 %o A008935 -- _Reinhard Zumkeller_, Jul 05 2011 %o A008935 (Python) %o A008935 a = lambda n: sum(((k+1)**2) * ((n >> k) & 1) for k in range(0, n.bit_length())) %o A008935 print([a(n) for n in range(1,68)]) # _Darío Clavijo_, Dec 27 2024 %Y A008935 Gives A003995 if sorted and duplicates removed. %K A008935 nonn,nice,easy %O A008935 1,2 %A A008935 _N. J. A. Sloane_ %E A008935 Corrected and extended by Larry Reeves (larryr(AT)acm.org), Mar 22 2000