cp's OEIS Frontend

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.

A385988 a(1) = 1, and for any n > 1, a(n) is the largest k < n such that a(1) + ... + a(k) is a power of 2.

Original entry on oeis.org

1, 1, 2, 3, 3, 3, 3, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23
Offset: 1

Views

Author

Rémy Sigrist, Jul 14 2025

Keywords

Comments

In other words: a(1) = 1, and for any n > 0, if a(1) + ... + a(n) is a power of 2 then a(n+1) = n, otherwise a(n+1) = a(n).
This sequence is unbounded: if a(1) + ... + a(n) = 2^i, let n = m * 2^j with m odd, note that n <= 2^i, so j <= i, let z be the multiplicative order of m modulo 2, let t = 2^(i-j) * (2^z - 1) / m, a(1) + ... + a(n) + t * n = 2^(z+i), so a(1) + ... + a(n) + u * n is a power of 2 for some u in the range n+1..t, and a(u+1) > a(n+1) = n.

Examples

			Sequence begins:
  n   a(n)  a(1)+...+a(n)  Power of 2?
  --  ----  -------------  -----------
   1     1              1  Yes
   2     1              2  Yes
   3     2              4  Yes
   4     3              7  No
   5     3             10  No
   6     3             13  No
   7     3             16  Yes
   8     7             23  No
   9     7             30  No
  10     7             37  No
  11     7             44  No
  12     7             51  No
		

Crossrefs

See A385986 for a similar sequence.
Cf. A386905 (distinct terms).

Programs

  • Mathematica
    Module[{s = -1, a = 1}, Table[If[DigitSum[s += a, 2] == 1, a = n - 1]; a, {n, 100}]] (* Paolo Xausa, Aug 07 2025 *)
  • PARI
    { v = 1; t = 0; for (n = 1, 71, print1(v", "); if (hammingweight(t += v)==1, v = n;);); }