OFFSET
0,4
LINKS
Rainer Rosenthal, Table of n, a(n) for n = 0..1000
FORMULA
a(n^2) = A000120(n). - Michel Marcus, Dec 15 2018
EXAMPLE
For n = 7 we have sqrt(7) = 2.64575131... with binary expansion 10.1010010.... Of the first 7 digits there are a(7) = 3 digits equal to 1.
MAPLE
zaehle := proc(n) local e, p, c, i, z, m; Digits := n+5; e := evalf(sqrt(n)); p := [op(convert(e, binary))]; c := convert(p[1], base, 10); z := 0; m := min(n, nops(c)); for i to m do if c[-i] = 1 then z := z+1; fi; od; return z; end: seq(zaehle(n), n=0..60); # Rainer Rosenthal, Dec 14 2018
a := n -> StringTools:-CountCharacterOccurrences(convert(convert(evalf(sqrt(n), n+5), binary, n), string), "1"): seq(a(n), n=0..60); # Peter Luschny, Dec 15 2018
MATHEMATICA
a[n_] := Count[RealDigits[Sqrt[n], 2, n][[1]], 1]; Array[a, 60, 0] (* Amiram Eldar, Dec 14 2018 *)
PROG
(PARI) a(n)=my(v=concat(binary(sqrt(n)))); hammingweight(v[1..n]) \\ Hugo Pfoertner, Dec 16 2018
CROSSREFS
KEYWORD
nonn,easy,base
AUTHOR
Rainer Rosenthal, Dec 14 2018
STATUS
approved