%% \documentclass[preprint,review,12pt]{elsarticle} %% Use the options 1p,twocolumn; 3p; 3p,twocolumn; 5p; or 5p,twocolumn %% for a journal layout. \documentclass[final,3p,times]{elsarticle} \usepackage[T1]{fontenc} \usepackage[utf8]{inputenc} \usepackage{url} \usepackage{hyperref} \hypersetup{colorlinks=true,allcolors=blue} \usepackage{amssymb} \usepackage{amsthm} \usepackage{amsmath} \usepackage{mathtools} \usepackage{caption} \usepackage{microtype} \usepackage{enumitem} \usepackage{xcolor} \usepackage{booktabs} \usepackage{array} \usepackage{float} \usepackage{algorithm} \usepackage{algpseudocode} \makeatletter \providecommand{\theHALG@line}{} \renewcommand{\theHALG@line}{\thealgorithm.\arabic{ALG@line}} \makeatother \theoremstyle{plain} \newtheorem{Theorem}{Theorem}[section] \newtheorem{Lemma}[Theorem]{Lemma} \newtheorem{Proposition}[Theorem]{Proposition} \newtheorem{Corollary}[Theorem]{Corollary} \theoremstyle{definition} \newtheorem{Definition}[Theorem]{Definition} \newtheorem{Example}[Theorem]{Example} \newtheorem{Remark}[Theorem]{Remark} \journal{Hexagon} \begin{document} \begin{frontmatter} \title{Powers of a Prime in the Image of Summatory Valuation Functions} \author{Frank Vega} \address{Information Physics Institute, 840 W 67th St, Hialeah, FL 33012, USA} \ead{vega.frank@gmail.com} \begin{abstract} J.-L. Nicolas asked how often a power of $2$ belongs to the image of $c(n)=\sum_{k\le n}2^{v_2(k)}$, where $v_2$ is the $2$-adic valuation, and showed that the number $A(x)$ of exponents $a\le x$ with $2^a$ in the image and the number $B(x)$ of the other exponents both tend to infinity. We prove that $2^a$ lies in the image of $c$ if and only if $2^{a+3}$ is a sum of distinct terms of the superincreasing sequence $(j2^j)_{j\ge1}$. For every exponent there is at most one possible largest term $K$, given by $K+\lceil\log_2K\rceil=a+3$, and membership is then decided by an explicit recursion on pairs of integers at most $a+3$, in at most $a+1$ steps. The exponents without such a $K$ and the exponents decided in at most one step form explicit infinite families, described completely, which contain the three families of Nicolas. The states of the recursion form a forest and the set of successful states is symmetric; this yields further explicit families and the bounds $A(x)\ge(3.9655\ldots+o(1))\log_2x$ and $B(x)\ge(2.8178\ldots+o(1))\log_2x$, whereas the families of Nicolas give the constants $\frac12$ and $\frac32$. The reduction, the unique candidate, the recursion and the symmetry extend to $c_p(n)=\sum_{k\le n}p^{v_p(k)}$ for every prime $p$. Computations in exact integer arithmetic reproduce the table of Nicolas and give $A(x)$ for $x\le262000$, with $A(x)/x$ between $0.5132$ and $0.8750$ for $x=1000,2000,\dots,262000$. \end{abstract} \begin{keyword} Arithmetic functions \sep $2$-adic valuation \sep Binary expansion \sep Superincreasing sequences \sep Polynomials over $\mathbb{F}_2$ \sep Open questions of Nicolas \MSC[2020] 11A63 \sep 11A25 \sep 11B83 \sep 11N37 \end{keyword} \end{frontmatter} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \section{Introduction} \label{sec:intro} For a positive integer $k$ let $v_2(k)$ denote the exponent of $2$ in $k$. In a joint paper with J.~Dixmier~\cite{dixmiernicolas2002}, J.-L.~Nicolas considered the function \begin{equation} \label{eq:cdef} c(n)=\sum_{k=1}^{n}2^{v_2(k)},\qquad n\ge1, \end{equation} which is the exponent of $1+X$ in the factorization of $(1+X)(1+X^2)\cdots(1+X^n)$ into irreducible factors over $\mathbb{F}_2[X]$, and in his list of open questions~\cite{nicolas2005open} he asked how often a power of $2$ belongs to the image of $c$. The sequence $(c(n))_{n\ge1}=1,3,4,8,9,11,12,20,\dots$ of the partial sums of the highest power of $2$ dividing $k$ is the sequence M2344 of the encyclopedia of Sloane and Plouffe~\cite{sloaneplouffe1995}. It satisfies the recurrence $c(2n)=2c(n)+n$ and the formulas $c(2^r)=2^{r-1}(r+2)$ and $c(2^r-1)=r2^{r-1}$~\cite{nicolas2005open}, and the recurrence splits at half, a class of recurrences whose identities and periodic oscillations are studied by Hwang, Janson and Tsai~\cite{hwangjansontsai2024}. With \begin{equation} \label{eq:Adef} \mathcal{A}=\{a\ge0:\ 2^a\in c(\mathbb{N})\},\qquad A(x)=\#\{a\in\mathcal{A}:\ a\le x\},\qquad B(x)=\#\{a\in\mathbb{Z}\cap[0,x]:\ a\notin\mathcal{A}\}, \end{equation} Nicolas showed that $A(x)\to\infty$ and $B(x)\to\infty$, and asked whether the behaviour of $A(x)$ can be made precise; his table gives, for instance, the values $635$ for $x=1000$ and $5963$ for $x=10000$~\cite{nicolas2005open}, which are the numbers of exponents $1\le a\le x$ in $\mathcal{A}$, that is $A(x)-1$ in the notation~\eqref{eq:Adef}, since $c(1)=2^0$ (Section~\ref{sec:experiments}). He obtained these limits from three families: $2^a\notin c(\mathbb{N})$ when $a=2^r+r-2$; $a+(2^a-11)/3\in\mathcal{A}$ for odd $a\ge3$; and $a+(2^a-10)/3\notin\mathcal{A}$ for even $a\ge4$~\cite{nicolas2005open}. The same list contains a question on a family of fractions, namely the size of the largest numerator $A(N)$ of $\prod_{n\le N}((n+1)/n)^{\varepsilon(n)}$ with $\varepsilon(n)\in\{-1,0,1\}$; for that question de la Bret\`eche, Pomerance and Tenenbaum proved $\log A(N)=\{\kappa+o(1)\}N\log N$ with an explicit constant $\kappa\approx0.107005$~\cite{bretechepomerancetenenbaum2005}. The present paper is concerned with the question on $c(n)$ only. \subsection{Related work} \label{subsec:related} The sequence $(c(n))_{n\ge1}$ is the entry A006520 of the On-Line Encyclopedia of Integer Sequences~\cite{oeisA006520}, where it is described as the sequence of the partial sums of the highest power of $2$ dividing $k$ and where the formula $c(n)=n+\sum_{k\ge1}2^{k-1}\lfloor n/2^k\rfloor$ is recorded. The relations $c(2n)=2c(n)+n$ and $c(2n+1)=2c(n)+n+1$, the second of which follows from the first because $v_2(2n+1)=0$, show that the $\mathbb{Z}$-module generated by the three sequences $(c(n))_{n\ge0}$, $(n)_{n\ge0}$ and $(1)_{n\ge0}$, with $c(0)=0$, is stable under the substitutions $n\mapsto2n$ and $n\mapsto2n+1$; hence $(c(n))_{n\ge0}$ is a $2$-regular sequence in the sense of Allouche and Shallit~\cite{alloucheshallit1992}. In the same way, for a prime $p$ the function $c_p$ of Section~\ref{sec:primes} satisfies $c_p(pn+r)=p\,c_p(n)+(p-1)n+r$ for $0\le r\le p-1$, by Lemma~\ref{lem:cp}(1) and because the integers $pn+1,\dots,pn+r$ are prime to $p$, so that $(c_p(n))_{n\ge0}$ is a $p$-regular sequence. The identities and the asymptotic oscillations of the solutions of recurrences splitting at half are the subject of~\cite{hwangjansontsai2024}; the question of Nicolas concerns the set of values of $c$. Nicolas~\cite{nicolas2005open} compares $c$ with the summatory function $S(n)=\sum_{k\le n}d(k)$ of the sum $d(k)$ of the binary digits of $k$: one has $S(2^r-1)=c(2^r-1)=r2^{r-1}$, the two functions are not equal, and he refers to the asymptotic study of $S(n)$ by Mellin transforms~\cite{flajoletetal1994}. A sequence of positive integers is called superincreasing if each term is larger than the sum of all the preceding terms. For such a sequence, an integer has at most one representation as a sum of distinct terms, and the representation, if it exists, is obtained by taking at each step the largest term that does not exceed the remainder; the knapsack scheme of Merkle and Hellman rests on this property~\cite{merklehellman1978}. Lemma~\ref{lem:greedy} is this property for the sequence $(j2^j)_{j\ge1}$. Sections~\ref{sec:leading}--\ref{sec:states} use the special form $j2^j$ of the terms and the special form $2^b$ of the target, for which the greedy procedure becomes the recursion on pairs of small integers of Section~\ref{sec:recursion}. With respect to the results of Nicolas, the comparison is the following. The three families of Nicolas contain $\frac12\log_2x+O(1)$ exponents $a\le x$ in $\mathcal{A}$ and $\frac32\log_2x+O(1)$ exponents $a\le x$ outside $\mathcal{A}$ (Proposition~\ref{prop:nicolascount}), and the families of the present paper contain at least $(3.9655\ldots+o(1))\log_2x$ exponents $a\le x$ in $\mathcal{A}$ and at least $(2.8178\ldots+o(1))\log_2x$ exponents $a\le x$ outside $\mathcal{A}$ (Theorem~\ref{thm:counting2}). Table~\ref{tab:allfam} gives the numbers of exponents of all these families up to $x=10^3,\dots,10^{12}$, together with the exact values of $A(x)$ and $B(x)$ for $x\le10^5$. Tables~\ref{tab:counting}, \ref{tab:counting65} and~\ref{tab:counting131} give $A(x)$ for $x\le260000$, and the values of Table~\ref{tab:counting} for $x\le10000$ coincide with the table of Nicolas. \paragraph{Contributions} We prove the following results. \begin{itemize} \item The identity $c(n)=n+\frac12\sum_{i\in\mathcal{B}(n)}i\,2^{i}$, where $\mathcal{B}(n)$ is the set of positions of the binary digits $1$ of $n$, equivalently $c(n)=n+\sum_{k\ge1}2^{k-1}\lfloor n/2^k\rfloor$, and the equivalence $a\in\mathcal{A}\iff 2^{a+3}=\sum_{j\in T}j\,2^{j}$ for a finite set $T$ of positive integers (Lemma~\ref{lem:cformula}, Theorem~\ref{thm:equiv}). \item The numbers $j2^j$ form a superincreasing sequence. Consequently, for every $a\ge0$ there is at most one integer $K\ge2$ that can be the largest element of $T$, namely the solution of $K+\lceil\log_2K\rceil=a+3$, and such a $K$ fails to exist exactly for $a=2^r+r-2$, $r\ge1$ (Theorem~\ref{thm:leading}). This recovers the first family of Nicolas and shows that it is the only obstruction of this kind. \item A recursion on pairs of integers bounded by $a+3$ that decides whether $a\in\mathcal{A}$ in at most $a+1$ steps, without handling integers of size $2^a$ (Theorem~\ref{thm:step}, Corollary~\ref{cor:algo}). \item Infinite explicit families of members of $\mathcal{A}$, given by the closed formula $c(2^{K-2}+2^{K-s-2})=2^{K+h-3}$ for $s=2^k$, $k\ge0$, $h\equiv k\pmod{2^{k+1}}$ and $K=(2^{h+s}+s)/(2^s+1)$ (Theorem~\ref{thm:members}), and infinite explicit families of non-members, indexed by $s=3$ and by $s=2^i$, $i\ge1$ (Theorem~\ref{thm:nonmembers}). The second and third families of Nicolas are the cases $s=1$ of Theorem~\ref{thm:members} and $s=2$ of Theorem~\ref{thm:nonmembers}. These families are complete in the following sense: they are exactly the exponents that Algorithm~\ref{alg:membership} decides in at most one iteration (Theorem~\ref{thm:firststep}). \item Explicit lower bounds for both counting functions (Theorem~\ref{thm:counting}): \[ A(x)\ge(2+o(1))\log_2x,\qquad B(x)\ge\Bigl(\frac54+\frac{E}{2}+o(1)\Bigr)\log_2x,\qquad E=\sum_{i\ge1}\frac{1}{2^i-1}=1.6066951\ldots, \] so that $\frac54+\frac E2=2.0533475\ldots$. \item The states of the recursion form a forest: the roots are the states $(J,0)$, one at each level, and the failing states, whose number up to level $L$ is given by an explicit formula; each state $(J',w')$ has exactly $v_2(J'+1+w')$ children; and the initial states are the states with $J+1+w$ a power of $2$ (Theorem~\ref{thm:forest}). The root of the tree of a successful state is determined by the least element of its representing set, and exactly half of the successful states of each level lie in the tree of the root $(1,0)$ (Proposition~\ref{prop:roots}). The sets $S_J$ satisfy the recursion $S_J=\{c/2:\ c\in S_{J-1}\text{ even}\}\cup\{(c+J)/2:\ c\in S_{J-1}\text{ odd}\}$ for odd $J$ and $S_J=\{c/2,\ c/2+J/2:\ c\in S_{J-1}\text{ even}\}$ for even $J$; in particular $S_J$ is periodic with period $J/2$ for even $J$ (Theorem~\ref{thm:bottomup}). The symmetry yields three further explicit families, among them $c(2^{2^r}-1)=2^{2^r+r-1}$ (Theorem~\ref{thm:symfamilies}), and the improved bounds $A(x)\ge(3.9655\ldots+o(1))\log_2x$ and $B(x)\ge(2.8178\ldots+o(1))\log_2x$ (Theorem~\ref{thm:counting2}). For the sets $S_J$ of successful states, which are the states in the trees of the roots $(J,0)$, the number $N(J)=|S_J|$ counts the sets $T\subseteq\{1,\dots,J\}$ with $\sum_{j\in T}j2^j\equiv0\pmod{2^{J+1}}$, $S_J$ is symmetric under $w\mapsto J-1-w$, $N(2k+1)=N(2k)$, and $4\mid N(J)$ for $J\ge4$ (Section~\ref{sec:states}). \item The analogue for every prime $p$ (Section~\ref{sec:primes}), with the complete description of the immediate failures, the bottom-up recursion and the symmetry $w\mapsto(p-1)K-w$ (Theorems~\ref{thm:immediate} and~\ref{thm:primebottomup}): $c_p(n)=\sum_{k\le n}p^{v_p(k)}$ is the exponent of $1-X$ in $(1-X)\cdots(1-X^n)$ over $\mathbb{F}_p[X]$; the reduction to digit sums of the numbers $p^i((p-1)i+p)$, the unique candidate, the exponents $(p^g-1)/(p-1)+g-1$ without candidate, the recursion, and explicit families, among them a family of non-members with no analogue for $p=2$ (Theorems~\ref{thm:primes}, \ref{thm:primestep} and~\ref{thm:primefamilies}). For a general prime, the exponents classified completely are those decided before the first step of the recursion: the exponents without candidate, the exponents accepted without any step (Proposition~\ref{prop:primezero}) and the immediate failures; the classification of the exponents decided in exactly one step (Theorem~\ref{thm:firststep}(2) and~(3)) and the forest of Theorem~\ref{thm:forest} are proved for $p=2$ only. Table~\ref{tab:scope} compares the two cases. \item Experiments (Section~\ref{sec:experiments}) with exact integer arithmetic: a verification of the statements above by three independent methods, among them a brute-force search over $n\le2^{24}$; the values of $A(x)$ and $B(x)$ for $x\le20000$, which agree with the table of Nicolas; the sets $S_J$ for $J\le65536$, from which $A(x)$ is obtained for $x\le65000$; the proportion of exponents in $\mathcal{A}$ among the candidates $K\in(2^{h-1},2^h]$ for $h\le16$; and the sets $S_J$ for $J\le262144$ computed with the recursion of Theorem~\ref{thm:bottomup}, from which $A(x)$ is obtained for $x\le262000$. \end{itemize} Section~\ref{subsec:related} places the results in the literature, Section~\ref{sec:reformulation} proves the identity and the equivalence, Section~\ref{sec:leading} treats the largest element of $T$, Section~\ref{sec:recursion} gives the recursion, Sections~\ref{sec:members} and~\ref{sec:nonmembers} give the explicit families, Section~\ref{sec:counting} proves the counting bounds, Section~\ref{sec:states} studies the successful states, Section~\ref{sec:primes} treats an arbitrary prime, Section~\ref{sec:experiments} reports the experiments and Section~\ref{sec:conclusion} concludes. \paragraph{Logical dependencies} The main results depend on each other as follows. Lemma~\ref{lem:cformula} gives Theorem~\ref{thm:equiv}. Lemmas~\ref{lem:sum} and~\ref{lem:greedy} give Theorem~\ref{thm:leading}. Theorem~\ref{thm:step} follows from Lemmas~\ref{lem:sum} and~\ref{lem:greedy}, and with Theorems~\ref{thm:equiv} and~\ref{thm:leading} it gives Corollary~\ref{cor:algo}; Lemma~\ref{lem:least} is a complement to Theorem~\ref{thm:step}. Theorem~\ref{thm:members} uses only Lemma~\ref{lem:cformula}, and Theorem~\ref{thm:nonmembers} uses Theorem~\ref{thm:step} and Lemma~\ref{lem:least}. Theorem~\ref{thm:firststep} follows from Lemmas~\ref{lem:least} and~\ref{lem:order} and Theorems~\ref{thm:members} and~\ref{thm:nonmembers}, and Proposition~\ref{prop:nicolasfamilies} identifies the families of Nicolas among these. Theorem~\ref{thm:counting} counts the exponents of Theorems~\ref{thm:leading}, \ref{thm:members} and~\ref{thm:nonmembers}. In Section~\ref{sec:states}, Propositions~\ref{prop:Ncount}, \ref{prop:symmetry} and~\ref{prop:Npairs} and Theorem~\ref{thm:bottomup} follow from Lemmas~\ref{lem:sum} and~\ref{lem:greedy}; Theorem~\ref{thm:forest} follows from Theorem~\ref{thm:step} and Lemma~\ref{lem:least}, and Proposition~\ref{prop:roots} from Theorem~\ref{thm:forest} and Proposition~\ref{prop:symmetry}; Theorem~\ref{thm:symfamilies} follows from Theorem~\ref{thm:forest} and Proposition~\ref{prop:symmetry}, and Theorem~\ref{thm:counting2} from Theorems~\ref{thm:counting} and~\ref{thm:symfamilies}. Section~\ref{sec:primes} is independent of Sections~\ref{sec:leading}--\ref{sec:states}: Lemma~\ref{lem:cp} gives Theorem~\ref{thm:primes}, which gives Theorems~\ref{thm:primestep} and~\ref{thm:primebottomup}; Theorems~\ref{thm:primefamilies} and~\ref{thm:immediate} and Proposition~\ref{prop:primezero} follow from Theorems~\ref{thm:primes} and~\ref{thm:primestep}. \paragraph{Notation} $\mathbb{N}=\{1,2,3,\dots\}$. For $n\ge1$, $\mathcal{B}(n)\subset\{0,1,2,\dots\}$ is the set of positions of the digits $1$ in the binary expansion of $n$, so that $n=\sum_{i\in\mathcal{B}(n)}2^i$. For $J\ge0$ we put \begin{equation} \label{eq:EJ} \mathcal{E}_J=\Bigl\{\sum_{j\in T}j\,2^{j}:\ T\subseteq\{1,\dots,J\}\Bigr\},\qquad \mathcal{E}=\bigcup_{J\ge0}\mathcal{E}_J, \end{equation} with $\mathcal{E}_0=\{0\}$ (empty sum). Thus $\mathcal{E}_J$ and $\mathcal{E}$ are sets of nonnegative integers, namely the values of the sums, and not sets of index sets; and $\mathcal{E}_0\subseteq\mathcal{E}_1\subseteq\mathcal{E}_2\subseteq\cdots$. We say that a finite set $T$ of positive integers \emph{represents} the integer $V$ if $\sum_{j\in T}j\,2^{j}=V$. Hence $V\in\mathcal{E}_J$ means that $V$ is represented by some $T\subseteq\{1,\dots,J\}$, and $V\in\mathcal{E}$ means that $V$ is represented by some finite set $T$ of positive integers. By Lemma~\ref{lem:greedy}, the set representing a given integer is unique, so that $T\mapsto\sum_{j\in T}j\,2^{j}$ is a bijection from the set of the subsets of $\{1,\dots,J\}$ onto $\mathcal{E}_J$; we call this $T$ \emph{the} set representing $V$. The index sets are always denoted by $T$ or $U$, and the integers they represent by $V$. The counting function $A(x)$ of~\eqref{eq:Adef} includes the exponent $a=0$, because $c(1)=2^0$; the values of the table of Nicolas~\cite{nicolas2005open} are the numbers $A(x)-1$ of exponents $1\le a\le x$ in $\mathcal{A}$. Table~\ref{tab:notation} lists the notation of the paper. As an illustration of the notation, take $a=5$. We have $2^{a+3}=256=5\cdot2^5+4\cdot2^4+3\cdot2^3+2\cdot2^2$, so the set $T=\{2,3,4,5\}$ represents $2^8$, and $2^8\in\mathcal{E}_5\subseteq\mathcal{E}$. The largest element of $T$ is $K=5$, with $h(K)=3$ and $\beta(K)=8=a+3$, so $K$ is the candidate of $a$, and the initial state of $a$ is $(K-1,2^{h(K)}-K)=(4,3)$. The integer $n=\sum_{j\in T}2^{j-2}=15$ satisfies $c(15)=32=2^5$, so $5\in\mathcal{A}$ (Theorem~\ref{thm:equiv} and Example~\ref{ex:algo}). \begin{table}[H] \centering \caption{Notation.} \label{tab:notation} \begin{tabular}{lp{0.66\textwidth}} \toprule Symbol & Meaning\\ \midrule $v_p(k)$ & exponent of the prime $p$ in the integer $k\ge1$\\ $c(n)$, $c_p(n)$ & $\sum_{k\le n}2^{v_2(k)}$ and $\sum_{k\le n}p^{v_p(k)}$ (\eqref{eq:cdef}, Section~\ref{sec:primes})\\ $\mathcal{A}$, $A(x)$, $B(x)$ & set of the exponents $a\ge0$ with $2^a\in c(\mathbb{N})$, and counting functions~\eqref{eq:Adef}\\ $\mathcal{B}(n)$ & set of the positions of the binary digits $1$ of $n$\\ $\mathcal{E}_J$, $\mathcal{E}$ & sets of the integers $\sum_{j\in T}j2^j$ with $T\subseteq\{1,\dots,J\}$, and their union~\eqref{eq:EJ}\\ $T$ represents $V$ & $\sum_{j\in T}j2^j=V$\\ $h(K)$, $\beta(K)$ & $\lceil\log_2K\rceil$ and $K+h(K)$~\eqref{eq:beta}\\ candidate $K$ of $a$ & the integer $K\ge2$ with $\beta(K)=a+3$, if it exists (Theorem~\ref{thm:leading})\\ state $(J,w)$ & pair of integers with $J\ge1$ and $0\le w\le J-1$; successful if $2^{J+1}w\in\mathcal{E}_J$ (Section~\ref{sec:recursion})\\ initial state of $a$ & the state $(K-1,2^{h(K)}-K)$, where $K$ is the candidate of $a$\\ $s$ & least integer $\sigma\ge1$ with $2^\sigma w+\sigma\ge J+1$, for a state $(J,w)$ with $w\ge1$ (Theorem~\ref{thm:step})\\ failing state & state $(J,w)$ with $w\ge1$ and $2^{s-1}w+s=J+1$ (Theorem~\ref{thm:step})\\ $\Phi(J,w)$ & the state $(J-s,2^sw+s-J-1)$, for a state $(J,w)$ with $w\ge1$ that does not fail (Section~\ref{sec:states})\\ $S_J$, $N(J)$, $F(J)$ & set and number of the successful states $(J,w)$, and number of the failing states $(J,w)$ (Section~\ref{sec:states})\\ $\mathcal{A}_p$, $A_p(x)$, $B_p(x)$ & analogues of $\mathcal{A}$, $A(x)$, $B(x)$ for $c_p$ (Section~\ref{sec:primes})\\ $t_i$, $\mathcal{E}^{(p)}_K$ & $p^i((p-1)i+p)$, and set of the sums $\sum_{0\le i\dots>n_t$ and applying this relation $t-1$ times gives $c(n)=\sum_{l=1}^{t}c(2^{n_l})=\sum_{i\in\mathcal{B}(n)}2^{i-1}(i+2)$. Finally $2^{i-1}(i+2)=\frac12 i2^i+2^i$ and $\sum_{i\in\mathcal{B}(n)}2^i=n$. \end{proof} The first equality of~\eqref{eq:cformula} is formula (7.4) of~\cite{nicolas2005open}. The second form is equivalent to $c(n)=n+\sum_{k\ge1}2^{k-1}\lfloor n/2^k\rfloor$: since $\lfloor n/2^k\rfloor=\sum_{i\in\mathcal{B}(n),\,i\ge k}2^{i-k}$, \[ \sum_{k\ge1}2^{k-1}\Bigl\lfloor\frac{n}{2^k}\Bigr\rfloor=\sum_{i\in\mathcal{B}(n)}\sum_{k=1}^{i}2^{k-1}2^{i-k}=\sum_{i\in\mathcal{B}(n)}i\,2^{i-1}. \] The binary form $\frac12\sum_{i\in\mathcal{B}(n)}i2^i$ is the one used below. \begin{Theorem} \label{thm:equiv} Let $a\ge0$. Then $a\in\mathcal{A}$ if and only if $2^{a+3}\in\mathcal{E}$. More precisely, if $T$ is a finite set of positive integers with $\sum_{j\in T}j2^j=2^{a+3}$, then $1\notin T$, and $n=\sum_{j\in T}2^{j-2}$ satisfies $c(n)=2^a$; conversely, if $c(n)=2^a$, then $T=\mathcal{B}(n)+2$ satisfies $\sum_{j\in T}j2^j=2^{a+3}$. \end{Theorem} \begin{proof} By~\eqref{eq:cformula}, $8c(n)=\sum_{i\in\mathcal{B}(n)}(i+2)2^{i+2}=\sum_{j\in\mathcal{B}(n)+2}j2^j$, which gives the converse part. For the direct part, every $j\ge2$ gives $j2^j\equiv0\pmod8$, while $1\cdot2^1=2$; since $2^{a+3}\equiv0\pmod 8$, $1\notin T$. As $2^{a+3}>0$, $T\neq\emptyset$, so $n=\sum_{j\in T}2^{j-2}$ is a positive integer with $\mathcal{B}(n)=T-2$, and $8c(n)=\sum_{j\in T}j2^j=2^{a+3}$. \end{proof} \section{The largest element of $T$} \label{sec:leading} \begin{Lemma} \label{lem:sum} For every $J\ge0$, $\sum_{j=1}^{J}j2^j=(J-1)2^{J+1}+2$. In particular $\max\mathcal{E}_J=(J-1)2^{J+1}+2<(J+1)2^{J+1}$. \end{Lemma} \begin{proof} The identity holds for $J=0$, and if it holds for $J$, then $(J-1)2^{J+1}+2+(J+1)2^{J+1}=J2^{J+2}+2$. The inequality is $2<2^{J+2}$. \end{proof} \begin{Lemma} \label{lem:greedy} Let $J\ge1$ and $V\in\mathcal{E}_J$ with $V>0$, and let $T\subseteq\{1,\dots,J\}$ with $\sum_{i\in T}i2^i=V$. Then $\max T$ is the largest $j\in\{1,\dots,J\}$ with $j2^j\le V$, and $T$ is unique. Consequently, if $V>0$ and $j$ is the largest element of $\{1,\dots,J\}$ with $j2^j\le V$, then $V\in\mathcal{E}_J$ if and only if $V-j2^j\in\mathcal{E}_{j-1}$. \end{Lemma} \begin{proof} Let $m=\max T$, so $m2^m\le V$. If some $j$ with $m\lceil\log_2K\rceil$ exactly when $K$ is a power of $2$, in which case the difference of the ceilings is $1$. Hence $\beta$ increases by $1$ at each step except from $K=2^r$ to $K=2^r+1$, where $\beta(2^r)=2^r+r$ and $\beta(2^r+1)=2^r+r+2$; since $\beta(2)=3$, the values $b\ge3$ not taken are exactly $2^r+r+1$, $r\ge1$. (3) Since $2^{h-1}0$ and $j=J+1-s$, so $2\le j\le J$. For $\sigma\in\{1,\dots,J\}$ and $i=J+1-\sigma$, the inequality $i2^i\le V$ is equivalent to $J+1-\sigma\le2^\sigma w$; hence the largest $i\le J$ with $i2^i\le V$ corresponds to the least admissible $\sigma$, that is $i=j$. By Lemma~\ref{lem:greedy}, $V\in\mathcal{E}_J$ if and only if $V-j2^j=2^j(2^sw-j)=2^jw'\in\mathcal{E}_{j-1}$, where $w'=2^sw-j=2^sw+s-J-1\ge0$. We bound $w'$ from above. If $s=1$, then $w'=2w-J\le J-2=j-2$. If $s\ge2$, the minimality of $s$ gives $2^{s-1}w+s-1\le J$, hence $2^sw\le2J+2-2s$ and $w'\le J+1-s=j$. Moreover $w'=j-1$ would mean $2^sw=2j-1$, which is impossible because $2^sw$ is even. Therefore either $w'\le j-2$ or $w'=j$, and $w'=j$ is equivalent to $2^sw=2j$, that is $2^{s-1}w+s=J+1$ (which cannot occur for $s=1$ since $w\le J-1$). In case (a), $w'=j$ and $2^jw'=j2^j>(j-2)2^j+2=\max\mathcal{E}_{j-1}$ by Lemma~\ref{lem:sum}, since $2^{j+1}>2$; hence $V\notin\mathcal{E}_J$. In case (b), $w'\le j-2=(J-s)-1$ and $J-s=j-1\ge1$, so $(J-s,w')$ is a state, and $2^jw'=2^{(J-s)+1}w'$, so $V\in\mathcal{E}_J$ if and only if $(J-s,w')$ is successful. \end{proof} \begin{algorithm}[H] \caption{Membership of $a$ in $\mathcal{A}$} \label{alg:membership} \begin{algorithmic}[1] \Require an integer $a\ge0$ \State $b\gets a+3$ \If{there is no $K\ge2$ with $K+\lceil\log_2K\rceil=b$} \State \Return $a\notin\mathcal{A}$ \EndIf \State $h\gets\lceil\log_2K\rceil$; $J\gets K-1$; $w\gets2^h-K$ \While{$w\ge1$} \State $s\gets$ least $\sigma\ge1$ with $2^\sigma w+\sigma\ge J+1$ \If{$2^{s-1}w+s=J+1$} \State \Return $a\notin\mathcal{A}$ \EndIf \State $w\gets2^sw+s-J-1$; $J\gets J-s$ \EndWhile \State \Return $a\in\mathcal{A}$ \end{algorithmic} \end{algorithm} \begin{Corollary} \label{cor:algo} Algorithm~\ref{alg:membership} decides whether $a\in\mathcal{A}$. It performs at most $K-2\le a+1$ iterations of the loop, and every integer it handles, other than the bound $2^h\le2K-2$ of the initial step, is at most $2K\le2a+6$. When it returns $a\in\mathcal{A}$, the indices $j=J+1-s$ produced at the successive iterations, together with $K$, form the set $T$ of Theorem~\ref{thm:equiv}, and $n=\sum_{j\in T}2^{j-2}$ satisfies $c(n)=2^a$. \end{Corollary} \begin{proof} Correctness follows from Theorems~\ref{thm:leading} and~\ref{thm:step}. Each iteration decreases $J$ by $s\ge1$ and keeps $J\ge1$, starting from $J=K-1$, so there are at most $K-2$ iterations; $K\le\beta(K)-1=a+2$. Throughout, $0\le w\le J-1\le K-2$, and in the computation of $s$ only $\sigma\le s$ are tested, with $2^{\sigma}w+\sigma\le2^sw+s\le2J+2-s\le2K$ for $s\ge2$ by the proof of Theorem~\ref{thm:step}, and $2w+1\le2K$ for $s=1$. The last statement follows from the proof of Theorem~\ref{thm:step} and Lemma~\ref{lem:greedy}. \end{proof} \begin{Example} \label{ex:algo} For $a=5$, $b=8=\beta(5)$, $h=3$ and the initial state is $(4,3)$. The loop gives $s=1$ and $(3,2)$, then $s=1$ and $(2,1)$, then $s=1$ and $(1,0)$, so $5\in\mathcal{A}$ with $T=\{5,4,3,2\}$ and $n=2^3+2^2+2+1=15$; indeed $c(15)=32$~\cite{nicolas2005open}. For $a=6$, $b=9=\beta(6)$, $h=3$ and the initial state is $(5,2)$; here $s=2$ and $2^{1}\cdot2+2=6=J+1$, so $6\notin\mathcal{A}$. \end{Example} The following lemma isolates the monotonicity and minimality properties of the integer $s$ of Theorem~\ref{thm:step} that are used in Sections~\ref{sec:nonmembers} and~\ref{sec:states}. We say that a state $(J,w)$ with $w\ge1$ \emph{fails} if case (2a) of Theorem~\ref{thm:step} holds, that is if $2^{s-1}w+s=J+1$. \begin{Lemma} \label{lem:least} Let $(J,w)$ be a state with $w\ge1$, put $f(\sigma)=2^\sigma w+\sigma$ for every integer $\sigma\ge0$, and let $s$ be the least integer $\sigma\ge1$ with $f(\sigma)\ge J+1$, as in Theorem~\ref{thm:step}. \begin{enumerate} \item The function $f$ is strictly increasing and $f(0)\le J-1$. Consequently an integer $\sigma\ge1$ is equal to $s$ if and only if $f(\sigma-1)\le J$ and $f(\sigma)\ge J+1$. \item If $\sigma\ge1$ and $2^{\sigma}w+\sigma=J+1$, then $s=\sigma$, the state $(J,w)$ does not fail, and the state $(J-s,w')$ of Theorem~\ref{thm:step}(2b) is $(J-\sigma,0)$. Conversely, if $(J,w)$ does not fail and $w'=0$, then $2^sw+s=J+1$. \item If $\sigma\ge2$ and $2^{\sigma-1}w+\sigma=J+1$, then $s=\sigma$ and the state $(J,w)$ fails. Conversely, if $(J,w)$ fails, then $s\ge2$ and $2^{s-1}w+s=J+1$. \end{enumerate} In particular, $(J,w)$ fails if and only if $2^{\sigma-1}w+\sigma=J+1$ for some integer $\sigma\ge2$, and $(J,w)$ reaches a state $(J',0)$ in one step of the recursion if and only if $2^{\sigma}w+\sigma=J+1$ for some integer $\sigma\ge1$; in both cases $\sigma$ is unique and equal to $s$. \end{Lemma} \begin{proof} (1) For $\sigma\ge0$, $f(\sigma+1)-f(\sigma)=2^\sigma w+1>0$, and $f(0)=w\le J-1$. By definition, $\sigma\ge1$ equals $s$ if and only if $f(\sigma)\ge J+1$ and $f(\tau)\le J$ for all $1\le\tau<\sigma$; since $f$ is increasing and $f(0)\le J$, the second condition is $f(\sigma-1)\le J$. (2) We have $f(\sigma)=J+1$ and $f(\sigma-1)\sigma$. So $s=\sigma$ by (1), and $2^{s-1}w+s=J+1$ is the condition of case (2a). Conversely, if $(J,w)$ fails, then $2^{s-1}w+s=J+1$, and $s=1$ would give $w=J$, contradicting $w\le J-1$; so $s\ge2$. The last statement follows from (2) and (3); the uniqueness of $\sigma$ holds because $\sigma=s$ in both cases. \end{proof} \section{Explicit members of $\mathcal{A}$} \label{sec:members} \begin{Theorem} \label{thm:members} \begin{enumerate} \item For every $r\ge1$, $c\bigl(2^{2^r-2}\bigr)=2^{2^r+r-3}$; thus $2^r+r-3\in\mathcal{A}$. \item Let $k\ge0$, $s=2^k$, and let $h\ge k+2$ with $h\equiv k\pmod{2^{k+1}}$. Then \begin{equation} \label{eq:Kmember} K=\frac{2^{h+s}+s}{2^s+1} \end{equation} is an integer with $2^{h-1}2^{h-1}$. As $h\ge k+2$, $s\le2^{h-2}$ and $K-s\ge2^{h-1}+1-2^{h-2}\ge2$. By Lemma~\ref{lem:cformula}, with $K-2>K-s-2\ge0$, \[ c\bigl(2^{K-2}+2^{K-s-2}\bigr)=2^{K-3}K+2^{K-s-3}(K-s)=2^{K-s-3}\bigl(K(2^s+1)-s\bigr)=2^{K-s-3}2^{h+s}=2^{K+h-3}. \] Since $2^{h-1}i$ with $h\equiv i\pmod{2(2^i-1)}$; \item $s=3$, and $h\equiv3\pmod4$. \end{enumerate} \end{Theorem} \begin{proof} Put $M=2^{s-1}+1$. Since $2^{s-1}\equiv-1\pmod M$, $2^{h+s-1}+s\equiv-2^h+s\equiv0\pmod M$, so $K$ is an integer. As $K=2^h-(2^h-s)/M$ with $0<2^h-s$ and $M\ge3$, we get $2^{h-1}i$. Case (2): $M=5$, $2^4\equiv1$ and $2^3\equiv3\pmod5$, so $h\equiv3\pmod4$ gives $2^h\equiv3=s$; and $3<2^h$ because $h\ge3$. \end{proof} For $s=2$ the condition is that $h\ge3$ is odd, $K=(2^{h+1}+2)/3$, and the exponent is $K+h-3=(h+1)+(2^{h+1}-10)/3$; with $a=h+1$ this is the family $a+(2^a-10)/3$, $a$ even, of Nicolas~\cite{nicolas2005open}. For $s=3$ and $h=3$, $K=7$ and $7\notin\mathcal{A}$; for $s=4$ and $h=8$, $K=228$ and $233\notin\mathcal{A}$. The families of Theorems~\ref{thm:members} and~\ref{thm:nonmembers} are exactly the exponents decided by at most one iteration of Algorithm~\ref{alg:membership}. \begin{Theorem} \label{thm:firststep} Let $a\ge0$ have a candidate $K$ (Theorem~\ref{thm:leading}), let $h=h(K)$, and let $(J,w)=(K-1,2^h-K)$ be the initial state. \begin{enumerate} \item Algorithm~\ref{alg:membership} returns $a\in\mathcal{A}$ without any iteration if and only if $K=2^h$, that is, $a$ is an exponent of Theorem~\ref{thm:members}(1). \item Algorithm~\ref{alg:membership} returns $a\in\mathcal{A}$ after exactly one iteration if and only if $a$ is an exponent of Theorem~\ref{thm:members}(2), that is, $K=(2^{h+s}+s)/(2^s+1)$ with $s=2^k$, $k\ge0$, $h\ge k+2$ and $h\equiv k\pmod{2^{k+1}}$. \item Algorithm~\ref{alg:membership} returns $a\notin\mathcal{A}$ at its first iteration if and only if $a$ is an exponent of Theorem~\ref{thm:nonmembers}(1) or~(2), that is, $K=(2^{h+s-1}+s)/(2^{s-1}+1)$ with either $s=2^i$, $i\ge1$, $h>i$ and $h\equiv i\pmod{2(2^i-1)}$, or $s=3$ and $h\equiv3\pmod4$. \end{enumerate} \end{Theorem} \begin{proof} Throughout the proof, $w=2^h-K$ and $J+1=K$, and $2^{h-1}s$. Hence $s=2^k$ for an integer $k\ge0$ (and $k\le s-1$ holds automatically), and $h\equiv k\pmod{2^{k+1}}$. Step 4. The condition $s<2^h$ of Step 2 is $kl$. This is case (1) of Theorem~\ref{thm:nonmembers} with $i=l\ge2$. Case (ii). The condition is $2^{s-1}+1-s=2^l$. For $s\ge4$ it is impossible, because $2^{s-2}<2^{s-1}+1-s<2^{s-1}$: the left inequality is $s<2^{s-2}+1$ and the right one is $s>1$. For $s=2$ it gives $l=0$, and the congruence is $h\equiv1\pmod2$; the condition $s<2^h$ is $h\ge2$, so $h\ge3$ is odd. This is case (1) of Theorem~\ref{thm:nonmembers} with $i=1$. For $s=3$ it gives $l=1$, and the congruence is $h\equiv3\pmod4$; then $h\ge3$ and $s<2^h$ holds. This is case (2) of Theorem~\ref{thm:nonmembers}. Step 4. By Steps 1--3, if the algorithm returns $a\notin\mathcal{A}$ at its first iteration, then $a=K+h-3$ is an exponent of Theorem~\ref{thm:nonmembers}(1) or~(2). Conversely, for the integers $s$, $h$ and $K$ of Theorem~\ref{thm:nonmembers}(1) or~(2), that theorem gives $2^{h-1}1$ and $h\equiv1\pmod2$, and $K=(2^{h+1}+2)/3$. Then $K+h-3=(h+1)+(2^{h+1}+2)/3-4=(h+1)+(2^{h+1}-10)/3$, and $h\mapsto a=h+1$ is a bijection from the odd integers $h\ge3$ onto the even integers $a\ge4$. \end{proof} The two further remarks of~\cite{nicolas2005open}, that $c(2^r)$ is a power of $2$ when $r+2$ is a power of $2$ and that $c(2^r-1)$ is a power of $2$ when $r$ is a power of $2$, are Theorem~\ref{thm:members}(1) and Theorem~\ref{thm:symfamilies}(1) below. \section{Counting functions} \label{sec:counting} \begin{Theorem} \label{thm:counting} As $x\to\infty$, \[ A(x)\ge2\log_2x-O(\log\log x),\qquad B(x)\ge\Bigl(\frac54+\frac E2\Bigr)\log_2x-O(\log\log x), \] where $E=\sum_{i\ge1}1/(2^i-1)=1.6066951\ldots$, so that $\frac54+\frac E2=2.0533475\ldots$. More precisely, for every $x\ge16$ and $H=\lfloor\log_2x\rfloor-1$, \[ A(x)\ge2H-\log_2H-3,\qquad B(x)\ge\Bigl(\frac54+\frac E2\Bigr)H-\log_2H-5. \] \end{Theorem} \begin{proof} Let $x\ge16$, $H=\lfloor\log_2x\rfloor-1\ge3$ and $\kappa=\lfloor\log_2H\rfloor$, so that $2^\kappa\le H<2^{\kappa+1}$. Step 1 (the exponents are at most $x$). If $1\le h\le H$ and $2\le K\le2^h$, then $\beta(K)-3\le2^h+h-3\le x/2+\log_2x\le x$. All the exponents produced by Theorems~\ref{thm:members} and~\ref{thm:nonmembers} are of the form $\beta(K)-3$ with $2^{h-1}\kappa}1/(2(2^i-1))\le\sum_{i>\kappa}2^{-i}=2^{-\kappa}<2/H$ and $\sum_{i\ge1}i/(2(2^i-1))\le\sum_{i\ge1}i2^{-i}=2$; and $\sum_{i\ge1}1/(2(2^i-1))=E/2$. Therefore \[ \sum_{i=1}^{\kappa}\Bigl(\frac{H-i}{2(2^i-1)}-1\Bigr)\ge\frac E2H-2-2-\kappa\ge\frac E2H-\log_2H-4. \] Theorem~\ref{thm:nonmembers}(2) gives one exponent for each integer $3\le h\le H$ with $h\equiv3\pmod4$; there are at least $H/4-1$ of them. Hence $B(x)\ge H+(\frac E2H-\log_2H-4)+(\frac H4-1)=(\frac54+\frac E2)H-\log_2H-5$. Step 5 (the asymptotic form). Since $\log_2x-2L$. Summing over $\sigma$ gives the formula. (2) Put $u=J'+1+w'$, so that $m=v_2(u)$. Since $0\le w'\le J'-1$, \begin{equation} \label{eq:urange} J'+1\le u\le2J'. \end{equation} Step 1 (every preimage has the stated form). Let $(J,w)$ be a state with $w\ge1$ that does not fail, with $\Phi(J,w)=(J',w')$, and let $s$ be its integer of Theorem~\ref{thm:step}. By the definition of $\Phi$, $J'=J-s$ and $w'=2^sw+s-J-1$. Hence $2^sw=w'+J+1-s=w'+J'+1=u$. So $2^s$ divides $u$, which gives $1\le s\le m$, and $J=J'+s$, $w=u/2^s$. Step 2 (the stated pairs are states). Let $1\le\sigma\le m$, $J=J'+\sigma$ and $w=u/2^\sigma$. Then $w$ is an integer, and $w\ge1$ because $u\ge1$. By~\eqref{eq:urange}, $w\le u/2\le J'=J-\sigma\le J-1$. So $(J,w)$ is a state with $w\ge1$. Step 3 (the integer $s$ of the state $(J,w)$ of Step 2 is $\sigma$). We have $2^\sigma w+\sigma=u+\sigma=J'+1+w'+\sigma=J+1+w'\ge J+1$. By~\eqref{eq:urange}, $2^{\sigma-1}w+\sigma-1=u/2+\sigma-1\le J'+\sigma-1=J-1\le J$. By Lemma~\ref{lem:least}(1), $s=\sigma$. Step 4 (the state $(J,w)$ of Step 2 does not fail). By~\eqref{eq:urange}, $2^{s-1}w+s=u/2+\sigma\le J'+\sigma=JM+2\sigma-2$. Put $J'=2^\sigma w-1\ge1$ and $J=J'+\sigma$. Since $v_2(J'+1)\ge\sigma$, Theorem~\ref{thm:forest}(2) shows that $(J,w)$ is a state that does not fail, with $\Phi(J,w)=(J',0)$; hence $w\in S_J$, and $J-1-w\in S_J$ by Proposition~\ref{prop:symmetry}. Moreover $2J-w=2^{\sigma+1}w+2\sigma-2-w=Mw+2\sigma-2=2^h$, so $w$ is even and, with $K=J+1$, $K=2^{h-1}+1+w/2$ and $2^h-K=J-1-w\in S_{K-1}$. Since $w\ge2$ and $w<2^h-2$, $2^{h-1}+11$; the integers $K$ of Theorems~\ref{thm:members}(2) and~\ref{thm:nonmembers} satisfy $K>2^h-2^h/3=\frac23\,2^h$, since there the denominators $2^s+1$ and $2^{s-1}+1$ are at least $3$. In Theorem~\ref{thm:symfamilies}(2) and~(3), $w/2$ is strictly decreasing in $\sigma$, and $K>2^{h-1}+1$; and for $h\ge3$ the integer $2^{h-1}+1$ of Theorem~\ref{thm:symfamilies}(1) differs from $2^h$ and from the integers of Theorem~\ref{thm:members}(2), which exceed $\frac23\,2^h$. Finally, an exponent in $\mathcal{A}$ and an exponent outside $\mathcal{A}$ are distinct. Hence, for $h\ge4$, the integers $K$ produced in the block $(2^{h-1},2^h]$ by the families of members are distinct, and so are those produced by the families of non-members. In the two counts below we use that, for integers $q\ge1$ and $n_0$, the number of integers $h\in[n_0,H]$ in a given residue class modulo $q$ is at least $(H-n_0+1)/q-1$, and that $2^{\kappa+1}>H$ for $\kappa=\lfloor\log_2H\rfloor$. Members. The proof of Theorem~\ref{thm:counting} gives at least $2H-\log_2H-3$ exponents. Theorem~\ref{thm:symfamilies}(1) gives the exponent $2^r+r-1$, whose candidate is $K=2^r+1=2^{h-1}+1$ with $h=r+1$, for each $4\le h\le H$; these are $H-3$ exponents. Theorem~\ref{thm:symfamilies}(2) gives, for each $1\le i\le\kappa$ and $\sigma=2^{i-1}+1$, one exponent for each integer $h\in[\sigma+2,H]$ with $h\equiv i\pmod{\sigma+1}$, and $\sigma+2\ge4$; the number of these $h$ is at least $(H-\sigma-1)/(\sigma+1)-1=H/(\sigma+1)-2$. Since $\sigma+1=2^{i-1}+2$ and $\sum_{i\ge1}1/(2^{i-1}+2)=C_1$, \[ \sum_{i=1}^{\kappa}\Bigl(\frac{H}{2^{i-1}+2}-2\Bigr)=C_1H-H\sum_{i>\kappa}\frac{1}{2^{i-1}+2}-2\kappa\ge C_1H-4-2\log_2H, \] because $\sum_{i>\kappa}1/(2^{i-1}+2)\le\sum_{i>\kappa}2^{1-i}=2^{1-\kappa}<4/H$. Adding the three contributions, \[ A(x)\ge(2H-\log_2H-3)+(H-3)+(C_1H-4-2\log_2H)=(3+C_1)H-3\log_2H-10. \] Non-members. The proof of Theorem~\ref{thm:counting} gives at least $(\frac54+\frac E2)H-\log_2H-5$ exponents. Theorem~\ref{thm:symfamilies}(3) gives, for each $2\le i\le\kappa$ and $\sigma=2^{i-1}+1$, one exponent for each integer $h\in[\sigma+1,H]$ with $h\equiv i\pmod\sigma$, and $\sigma+1\ge4$; the number of these $h$ is at least $(H-\sigma)/\sigma-1=H/\sigma-2$. Since $\sum_{i\ge2}1/(2^{i-1}+1)=\sum_{k\ge1}1/(2^k+1)=C_2$ and $\sum_{i>\kappa}1/(2^{i-1}+1)\le2^{1-\kappa}<4/H$, \[ \sum_{i=2}^{\kappa}\Bigl(\frac{H}{2^{i-1}+1}-2\Bigr)\ge C_2H-4-2\log_2H. \] Hence $B(x)\ge(\frac54+\frac E2+C_2)H-3\log_2H-9$. Since $H\ge\log_2x-2$ and $\log_2H\le\log_2\log_2x$, the asymptotic bounds follow. In these bounds, the term $1$ of $3+C_1$ comes from Theorem~\ref{thm:symfamilies}(1), and the terms $C_1$ and $C_2$ come from Theorem~\ref{thm:symfamilies}(2) and~(3), that is, from the images under the symmetry $w\mapsto J-1-w$ of Proposition~\ref{prop:symmetry} of the states $(J,w)$ that reach a state $(J',0)$ in one step and of the failing states, respectively. \end{proof} \section{The analogue for an arbitrary prime} \label{sec:primes} Let $p$ be a prime and $v_p$ the $p$-adic valuation. Put \[ c_p(n)=\sum_{k=1}^{n}p^{v_p(k)},\qquad \mathcal{A}_p=\{a\ge0:\ p^a\in c_p(\mathbb{N})\},\qquad A_p(x)=\#\{a\in\mathcal{A}_p:\ a\le x\}, \] and $B_p(x)=\#\{a\in\mathbb{Z}\cap[0,x]:\ a\notin\mathcal{A}_p\}$, so that $c_2=c$, $\mathcal{A}_2=\mathcal{A}$, $A_2=A$ and $B_2=B$. The interpretation of $c$ recalled in Section~\ref{sec:intro} extends to every prime. \begin{Proposition} \label{prop:Fp} For every $n\ge1$, $c_p(n)$ is the exponent of $1-X$ in the factorization of $(1-X)(1-X^2)\cdots(1-X^n)$ into irreducible factors over $\mathbb{F}_p[X]$. \end{Proposition} \begin{proof} Write $k=p^vk'$ with $p\nmid k'$. In characteristic $p$, $1-X^k=(1-X^{k'})^{p^v}$, and $1-X^{k'}=(1-X)(1+X+\dots+X^{k'-1})$, where the second factor takes the value $k'\neq0$ at $X=1$; hence $1-X$ divides $1-X^k$ exactly $p^v=p^{v_p(k)}$ times, and the exponents add up over $k\le n$. \end{proof} \begin{Lemma} \label{lem:cp} \begin{enumerate} \item For every $n\ge1$, $c_p(pn)=p\,c_p(n)+(p-1)n$. \item For every $m\ge0$, $c_p(p^m-1)=m(p-1)p^{m-1}$ and $c_p(p^m)=p^{m-1}\bigl((p-1)m+p\bigr)$. \item If $n=\sum_{i\ge0}d_ip^i$ is the expansion of $n$ in base $p$, then $c_p(n)=\sum_{i\ge0}d_i\,p^{i-1}\bigl((p-1)i+p\bigr)$. \end{enumerate} \end{Lemma} \begin{proof} (1) Among $k\le pn$, the $(p-1)n$ integers prime to $p$ contribute $1$ each, and $k=pk_1$ with $k_1\le n$ contributes $p\cdot p^{v_p(k_1)}$. (2) For $0\le v\le m-1$, exactly $(p-1)p^{m-1-v}$ integers $k\in[1,p^m-1]$ have $v_p(k)=v$, which gives $c_p(p^m-1)$, and $c_p(p^m)=c_p(p^m-1)+p^m$. (3) Let $m\ge0$, $1\le d\le p-1$ and $0\le spu$. Hence $\gamma=g(K)$. Since $p^{g(K)}\le pu2p-1$, so $K\ge0$. Put $u=(p-1)K+p=(p^g+1)/2$. Then $u=(p-1)(K+1)+1\le p^g$ and $p^g\le p(u-1)=p(p^g-1)/2$ because $p\ge3$, so $g(K)=g$ by the proof of Theorem~\ref{thm:primes}(3), and $K+g-1$ has candidate $K$. Moreover $d=\lfloor p^g/u\rfloor=\lfloor2p^g/(p^g+1)\rfloor=1$ and $w_0=p^g-u=u-1=(p-1)K+p-1>(p-1)K$, so $K+g-1\notin\mathcal{A}_p$ by Theorem~\ref{thm:primestep}(1). For the counting statement, the exponents of (1), of (3) and of Theorem~\ref{thm:primes}(3) are at most $p^{g}/(p-1)+g$ for the corresponding $g$, so those with $g\le\log_px-1$ are at most $x$ for large $x$; there are $\log_px-O(1)$ values of $g$ in (1) and in Theorem~\ref{thm:primes}(3), and $\frac12\log_px-O(1)$ even values in (3). Members and non-members are distinct, the exponents of Theorem~\ref{thm:primes}(3) have no candidate, and distinct $g$ give distinct $K$ and hence, by Theorem~\ref{thm:primes}(3), distinct exponents. \end{proof} For $p=3$, Theorem~\ref{thm:primefamilies} gives $c_3(27)=81$, so $4\in\mathcal{A}_3$, and $2\notin\mathcal{A}_3$; Theorem~\ref{thm:primes}(3) gives $1\notin\mathcal{A}_3$; and $c_3(13)=c_3(1)+c_3(3)+c_3(9)=1+5+21=27$, so $3\in\mathcal{A}_3$. The exponents rejected by the condition $w_0\le(p-1)K$ of Theorem~\ref{thm:primestep}(1), which we call \emph{immediate failures}, admit a complete description. \begin{Theorem} \label{thm:immediate} Let $a\ge0$ have the candidate $K$, and put $g=a+1-K$ and $u=(p-1)K+p$. Then $a$ is an immediate failure if and only if $u\mid p^g+j$ for some $j\in\{1,\dots,p-1\}$; in that case $e=(p^g+j)/u$ satisfies $2\le e\le p-1$. Consequently, there are no immediate failures for $p=2$; for $p=3$ the immediate failures are exactly the exponents of Theorem~\ref{thm:primefamilies}(3); and for every prime $p$ the immediate failures are the exponents $K+g-1$ obtained from the triples $(g,e,j)$ with $2\le e\le p-1$, $1\le j\le p-1$, $e\mid p^g+j$, $u=(p^g+j)/e\equiv1\pmod{p-1}$, $u\ge p$ and $u\le p^g\le p(u-1)$, through $K=(u-p)/(p-1)$. In particular, there are at most $(p-1)(p-2)$ immediate failures with a given $g$. \end{Theorem} \begin{proof} Step 1 (the quantities $d$ and $w_0$). Since $K$ is the candidate of $a$, $g=g(K)$, and the proof of Theorem~\ref{thm:primes}(3) gives $u\le p^g\le p(u-1)$. Hence $d=\lfloor p^g/u\rfloor$ satisfies $1\le d\le p-1$, and $w_0=p^g-du$ satisfies $0\le w_0u-p$. This proves the first statement, with $e=d+1$. Step 3 (the range of $e$). By Step 1, $e=d+1\ge2$; and $eu=p^g+j\le p(u-1)+p-1p-1$, a remainder $w'>(p-1)i$, and success.} \label{tab:primes} \begin{tabular}{rrrrr} \toprule & $p=3$ & $p=5$ & $p=7$ & $p=11$\\ \midrule $A_p(500)$ & $381$ & $239$ & $212$ & $215$\\ $A_p(1000)$ & $733$ & $397$ & $556$ & $397$\\ $A_p(1500)$ & $1105$ & $616$ & $896$ & $577$\\ $A_p(2000)$ & $1442$ & $882$ & $1173$ & $804$\\ $A_p(2500)$ & $1893$ & $1252$ & $1485$ & $1100$\\ $A_p(3000)$ & $2317$ & $1676$ & $1812$ & $1334$\\ $A_p(3500)$ & $2675$ & $2063$ & $2074$ & $1524$\\ $A_p(4000)$ & $3082$ & $2413$ & $2348$ & $1718$\\ $A_p(4500)$ & $3483$ & $2753$ & $2606$ & $1955$\\ $A_p(5000)$ & $3879$ & $3012$ & $2858$ & $2221$\\ $A_p(5500)$ & $4277$ & $3300$ & $3127$ & $2449$\\ $A_p(6000)$ & $4664$ & $3611$ & $3406$ & $2677$\\ $A_p(6000)/6000$ & $0.7773$ & $0.6018$ & $0.5677$ & $0.4462$\\ \midrule no candidate & $8$ & $6$ & $5$ & $4$\\ immediate failure & $4$ & $7$ & $8$ & $11$\\ digit $d>p-1$ & $675$ & $596$ & $343$ & $370$\\ remainder $w'>(p-1)i$ & $650$ & $1781$ & $2239$ & $2939$\\ success & $4664$ & $3611$ & $3406$ & $2677$\\ \bottomrule \end{tabular} \end{table} For $p=3$ the $4$ immediate failures up to $6000$ are the exponents $2,22,186,1646$ of Theorem~\ref{thm:primefamilies}(3), as Theorem~\ref{thm:immediate} states. Grouping the candidates by $g$, the proportion of members is $0.6667$, $0.7778$, $0.7037$, $0.8395$, $0.6626$, $0.7586$, $0.7796$ for $g=2,\dots,8$ when $p=3$; $0.4000$, $0.6400$, $0.5200$, $0.3952$, $0.6474$ for $g=2,\dots,6$ when $p=5$; $0.2857$, $0.6735$, $0.4052$, $0.6318$ for $g=2,\dots,5$ when $p=7$; and $0.1818$, $0.6198$, $0.3681$ for $g=2,3,4$ when $p=11$. \subsection{Immediate failures and the bottom-up recursion for odd primes} \label{subsec:primes2-exp} For $a\le100000$, the script determines the immediate failures from the first step of Theorem~\ref{thm:primestep} and compares them with the exponents given by the triples $(g,e,j)$ of Theorem~\ref{thm:immediate}. For $p=2$ there is none. For $p=3,5,7,11$ the two sets coincide; they are listed in Table~\ref{tab:immediate}. For $p=3$ they are the exponents of Theorem~\ref{thm:primefamilies}(3), and for every $p$ and $g$ their number is at most $(p-1)(p-2)$; the largest number for a single $g$ is $1,3,4,6$ for $p=3,5,7,11$. \begin{table}[H] \centering \caption{The immediate failures $a\le100000$ (Theorem~\ref{thm:immediate}).} \label{tab:immediate} \begin{tabular}{rl} \toprule $p$ & immediate failures $a\le100000$\\ \midrule $2$ & none\\ $3$ & $2,22,186,1646,14770$\\ $5$ & $2,3,41,54,80,1306,1957,24420,32558,48834$\\ $7$ & $2,4,20,82,102,202,3272,4906,6540,9808$\\ $11$ & $2,3,4,6,20,185,246,368,490,734,3224,19688,25312,29530,44293,59056,88582$\\ \bottomrule \end{tabular} \end{table} The script computes the sets $S^{(p)}_K$ for $K\le20000$ with Theorem~\ref{thm:primebottomup}, in at most $13.8$ seconds for each prime. For every $K\le20000$ and $p=3,5,7,11$, $S^{(p)}_K$ is symmetric under $w\mapsto(p-1)K-w$, $N_p(K+1)=N_p(K)$ when $p\nmid K$, and $N_p(K+1)=p\,\#\{w\in S^{(p)}_K:\ p\mid w\}$ when $p\mid K$; the members obtained from these sets coincide with those of Theorem~\ref{thm:primestep} for $a\le1500$. Table~\ref{tab:primes10000} gives $A_p(x)$ for $x\le20000$. Table~\ref{tab:primegroups} groups the candidates $K$ by $g=g(K)$ and compares the proportion of members with the mean of $N_p(K)/((p-1)K+1)$, the proportion of successful states, over the same $K$. For every complete group with at least $2000$ candidates, namely $g=8,9$ for $p=3$, $g=6,7$ for $p=5$, $g=5,6$ for $p=7$ and $g=5$ for $p=11$, the two numbers differ by at most $0.0110$. \begin{table}[H] \centering \caption{The counting functions $A_p(x)$ for $x\le20000$, obtained from Theorem~\ref{thm:primebottomup}.} \label{tab:primes10000} \begin{tabular}{rrrrrrrr} \toprule $x$ & $A_3(x)$ & $A_5(x)$ & $A_7(x)$ & $A_{11}(x)$ & $A_3(x)/x$ & $A_5(x)/x$ & $A_7(x)/x$\\ \midrule $2000$ & $1442$ & $882$ & $1173$ & $804$ & $0.7210$ & $0.4410$ & $0.5865$\\ $4000$ & $3082$ & $2413$ & $2348$ & $1718$ & $0.7705$ & $0.6032$ & $0.5870$\\ $6000$ & $4664$ & $3611$ & $3406$ & $2677$ & $0.7773$ & $0.6018$ & $0.5677$\\ $8000$ & $5684$ & $4866$ & $4764$ & $3576$ & $0.7105$ & $0.6082$ & $0.5955$\\ $10000$ & $6518$ & $6097$ & $6244$ & $4433$ & $0.6518$ & $0.6097$ & $0.6244$\\ $12000$ & $7196$ & $7327$ & $7670$ & $5260$ & $0.5997$ & $0.6106$ & $0.6392$\\ $14000$ & $8166$ & $8712$ & $9035$ & $6162$ & $0.5833$ & $0.6223$ & $0.6454$\\ $16000$ & $9353$ & $10011$ & $10038$ & $7033$ & $0.5846$ & $0.6257$ & $0.6274$\\ $18000$ & $10490$ & $11328$ & $11015$ & $7916$ & $0.5828$ & $0.6293$ & $0.6119$\\ $20000$ & $11757$ & $12576$ & $11997$ & $8787$ & $0.5878$ & $0.6288$ & $0.5998$\\ \bottomrule \end{tabular} \end{table} \begin{table}[H] \centering \caption{Candidates $K$ grouped by $g=g(K)$: number of candidates, proportion of members, and mean of $N_p(K)/((p-1)K+1)$ over the group (complete groups only).} \label{tab:primegroups} \begin{tabular}{rrrrr@{\qquad}rrrrr} \toprule $p$ & $g$ & candidates & members & mean density & $p$ & $g$ & candidates & members & mean density\\ \midrule $3$ & $5$ & $81$ & $0.8395$ & $0.7932$ & $5$ & $6$ & $3125$ & $0.6474$ & $0.6513$\\ $3$ & $6$ & $243$ & $0.6626$ & $0.6559$ & $5$ & $7$ & $15625$ & $0.6357$ & $0.6332$\\ $3$ & $7$ & $729$ & $0.7586$ & $0.7565$ & $7$ & $4$ & $343$ & $0.4052$ & $0.4243$\\ $3$ & $8$ & $2187$ & $0.7796$ & $0.7686$ & $7$ & $5$ & $2401$ & $0.6318$ & $0.6319$\\ $3$ & $9$ & $6561$ & $0.6033$ & $0.6005$ & $7$ & $6$ & $16807$ & $0.6018$ & $0.6085$\\ $5$ & $4$ & $125$ & $0.5200$ & $0.5304$ & $11$ & $4$ & $1331$ & $0.3681$ & $0.3926$\\ $5$ & $5$ & $625$ & $0.3952$ & $0.4173$ & $11$ & $5$ & $14641$ & $0.4446$ & $0.4405$\\ \bottomrule \end{tabular} \end{table} For $x=1000,2000,\dots,20000$, the ratio $A_p(x)/x$ takes values between $0.5828$ and $0.7773$ for $p=3$, between $0.3970$ and $0.6293$ for $p=5$, between $0.5560$ and $0.6454$ for $p=7$, and between $0.3970$ and $0.4486$ for $p=11$. For $a\le100000$ and $p=2,3,5,7,11$, the script determines the exponents with a candidate and $w_0=0$, and compares them with Proposition~\ref{prop:primezero}. For each of these primes, $w_0=0$ holds exactly when $u=p^g$, the exponents found are exactly the exponents $K+g-1$ with $K=(p^g-p)/(p-1)$, and the recursion of Theorem~\ref{thm:primestep} accepts each of them without any step. There are $16$ of them for $p=2$, namely $0,3,8,17,\dots,32780,65549$, the exponents of Theorem~\ref{thm:members}(1); $11$ for $p=3$, namely $0,4,14,42,124,368,1098,3286,9848,29532,88582$; $8$ for $p=5$, namely $0,6,32,158,784,3910,19536,97662$; $6$ for $p=7$, namely $0,8,58,402,2804,19612$; and $5$ for $p=11$, namely $0,12,134,1466,16108$. The equality $c_p(p^K)=p^{K+g-1}$ holds for every $K=(p^g-p)/(p-1)\le3000$, that is for $11,7,5,5,4$ values of $g$ when $p=2,3,5,7,11$. \section{Conclusion} \label{sec:conclusion} The identity $c(n)=n+\frac12\sum_{i\in\mathcal{B}(n)}i2^i$ turns the question of Nicolas into the question of which powers of $2$ are sums of distinct terms of the superincreasing sequence $(j2^j)_{j\ge1}$ (Theorem~\ref{thm:equiv}). For every exponent there is at most one possible leading term, and the exponents without one are exactly $2^r+r-2$ (Theorem~\ref{thm:leading}); the remaining exponents are decided by a recursion on pairs of integers bounded by $a+3$ (Theorem~\ref{thm:step}, Corollary~\ref{cor:algo}). The closed formula $c(2^{K-2}+2^{K-s-2})=2^{K+h-3}$ and the failure criterion of Theorem~\ref{thm:step} give infinite explicit families of members and of non-members, which contain the families of Nicolas as the cases $s=1$ and $s=2$ (Theorems~\ref{thm:members} and~\ref{thm:nonmembers}) and are exactly the exponents decided by at most one iteration of the recursion (Theorem~\ref{thm:firststep}), and they give the bounds $A(x)\ge(2+o(1))\log_2x$ and $B(x)\ge(2.0533\ldots+o(1))\log_2x$ (Theorem~\ref{thm:counting}). The experiments of Section~\ref{sec:experiments} confirm these statements by three independent methods, reproduce the table of Nicolas, whose values are the numbers $A(x)-1$ of exponents $1\le a\le x$ in $\mathcal{A}$, and give $A(x)$ for $x\le65000$, with $A(x)/x$ between $0.5132$ and $0.8654$ for $x=1000,2000,\dots,65000$. The successful states satisfy the symmetry $w\mapsto J-1-w$, $N(2k+1)=N(2k)$ and $4\mid N(J)$ (Propositions~\ref{prop:symmetry} and~\ref{prop:Npairs}), and for $7\le h\le16$ the proportion of members among the candidates $K\in(2^{h-1},2^h]$ differs from the mean of $N(K-1)/(K-1)$ by at most $0.0171$. The states form a forest whose roots are the states $(J,0)$ and the failing states, with $v_2(J'+1+w')$ children at each state $(J',w')$ (Theorem~\ref{thm:forest}); exactly half of the successful states of each level lie in the tree of $(1,0)$ (Proposition~\ref{prop:roots}), and at the levels $2^m\le65536$ the ten largest trees contain between $89.31\%$ and $100\%$ of the states of the level. The sets $S_J$ also satisfy a recursion from the smallest elements of $T$ upwards, with period $J/2$ for even $J$ (Theorem~\ref{thm:bottomup}); with this recursion $A(x)$ is computed for $x\le262000$, and $A(x)/x$ lies between $0.5132$ and $0.8750$ for $x=1000,2000,\dots,262000$. The symmetry gives further explicit families and the bounds $A(x)\ge(3.9655\ldots+o(1))\log_2x$ and $B(x)\ge(2.8178\ldots+o(1))\log_2x$ (Theorems~\ref{thm:symfamilies} and~\ref{thm:counting2}). For every prime $p$, the function $c_p(n)=\sum_{k\le n}p^{v_p(k)}$, which counts the factor $1-X$ in $(1-X)\cdots(1-X^n)$ over $\mathbb{F}_p[X]$, admits the same reduction, a unique candidate and a recursion, and for odd $p$ there are infinitely many members and non-members (Theorems~\ref{thm:primes}, \ref{thm:primestep} and~\ref{thm:primefamilies}); the immediate failures, which do not occur for $p=2$, are described completely, and the bottom-up recursion and the symmetry extend to every prime (Theorems~\ref{thm:immediate} and~\ref{thm:primebottomup}). The asymptotic behaviour of $A(x)$ asked for in~\cite{nicolas2005open} is not determined by these results. \subsection*{Declaration of interests} The author declares no competing interests. \subsection*{Funding sources} This research did not receive any specific grant from funding agencies in the public, commercial, or not-for-profit sectors. \subsection*{Declaration of generative AI in scientific writing} The author used Claude Opus 5.5 to assist in deriving the proofs, to write the experiment script \texttt{powers\_of\_two\_c.py}, and in preparing this manuscript; the author ran the experiments. After using this tool, the author reviewed and edited the content as needed and takes full responsibility for the content of the publication. \subsection*{Data availability} The experiments of Section~\ref{sec:experiments} are reproduced by running the script \texttt{powers\_of\_two\_c.py} with the options \texttt{--xmax 20000 --jmax2 262144 --pxmax 6000 --primes 3,5,7,11 --kmax 20000}, using Python~3.12.3 and NumPy~2.4.6. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \bibliographystyle{elsarticle-num} \bibliography{biblio} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \end{document}