%% \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 both the number $A(x)$ of exponents $a\le x$ with $2^a$ in the image and the number $B(x)$ of the other exponents tend to infinity. We prove the identity $c(n)=n+\frac12\sum_{i}i\,2^{i}$, the sum running over the positions of the binary digits $1$ of $n$, so 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 no such $K$ exists exactly when $a=2^r+r-2$. The remaining exponents are decided by an explicit recursion on pairs of integers bounded by $a+3$, in at most $a+1$ steps. We give the closed formula $c(2^{K-2}+2^{K-s-2})=2^{K+h-3}$ for $s=2^k$, $h\equiv k\pmod{2^{k+1}}$ and $K=(2^{h+s}+s)/(2^s+1)$, and infinite explicit families of exponents $a$ for which $2^a$ is not in the image, indexed by $s=3$ and $s=2^i$; the families given by Nicolas are the cases $s=1$ and $s=2$. As a consequence, $A(x)\ge(2+o(1))\log_2x$ and $B(x)\ge(\frac54+\frac12\sum_{i\ge1}\frac{1}{2^i-1}+o(1))\log_2x=(2.0533\ldots+o(1))\log_2x$. We prove that the states of the recursion form a forest, rooted at the states $(J,0)$ and at the failing states, in which every state $(J',w')$ has exactly $v_2(J'+1+w')$ children; that the sets $S_J$ of successful states are symmetric; that exactly half of them lie in the tree of the root $(1,0)$; that $N(2k+1)=N(2k)$; that $4\mid N(J)$ for $J\ge4$; and that $S_J$ satisfies a recursion from the smallest elements upwards, with period $J/2$ for even $J$. The symmetry gives further explicit families, among them $c(2^{2^r}-1)=2^{2^r+r-1}$, 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$. For every prime $p$, the function $c_p(n)=\sum_{k\le n}p^{v_p(k)}$ counts the factor $1-X$ in $(1-X)\cdots(1-X^n)$ over $\mathbb{F}_p$; we extend to it the reduction, the unique candidate, the recursions and the symmetry, give explicit families, and describe completely the exponents rejected at the first step, which occur only for odd $p$. We also report experiments in exact integer arithmetic: every statement is checked by three independent methods, the values of $A(x)$ reproduce the table of Nicolas, the sets $S_J$ are computed for $J\le131072$, and $A(x)/x$ lies between $0.5132$ and $0.8750$ for $x=1000,2000,\dots,131000$. \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, 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$; and $a+(2^a-10)/3\notin\mathcal{A}$ for even $a$~\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. \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}). The sets $S_J$ of successful states, 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}). \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$; and the proportion of exponents in $\mathcal{A}$ among the candidates $K\in(2^{h-1},2^h]$ for $h\le16$. \end{itemize} 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{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). \section{The function $c(n)$ and sums of $j2^j$} \label{sec:reformulation} \begin{Lemma} \label{lem:cformula} For every $r\ge0$, $c(2^r)=2^{r-1}(r+2)$, and for every $n\ge1$, \begin{equation} \label{eq:cformula} c(n)=\sum_{i\in\mathcal{B}(n)}2^{i-1}(i+2)=n+\frac12\sum_{i\in\mathcal{B}(n)}i\,2^{i}. \end{equation} \end{Lemma} \begin{proof} For $r\ge0$, the number of $k\in[1,2^r-1]$ with $v_2(k)=v$ is $2^{r-1-v}$ for $0\le v\le r-1$, so $c(2^r-1)=\sum_{v=0}^{r-1}2^v2^{r-1-v}=r2^{r-1}$ and $c(2^r)=r2^{r-1}+2^r=2^{r-1}(r+2)$. If $m\ge0$ and $1\le s<2^m$, then $v_2(2^m+k)=v_2(k)$ for $1\le k\le s$, hence $c(2^m+s)=c(2^m)+c(s)$. Writing $n=2^{n_1}+\dots+2^{n_t}$ with $n_1>\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} 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} \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}0$. Hence Theorem~\ref{thm:step}(2a) applies, and the state is not successful. Case (1): $M=2^{s-1}+1$ with $s=2^i$, so $2^{2(s-1)}\equiv1\pmod M$ and $h=i+2(s-1)q$ gives $2^h\equiv2^i=s$; and $s=2^i<2^h$ because $h>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} (1) The loop is not entered if and only if $w=0$, that is $K=2^h$. We use the following fact on residues. Let $m\ge1$ and $N=2^m+1$. Since $2^m\equiv-1\pmod N$, the residues of the powers $2^e$, $e\ge0$, are $2^l$ and $N-2^l$ for $0\le l\le m-1$; these $2m$ residues are distinct, because $N-2^l\ge2^{m-1}+1>2^{m-1}\ge2^{l'}$, so $2$ has order $2m$ modulo $N$ and $2^e\equiv2^l\pmod N$ with $0\le l\le m-1$ holds if and only if $e\equiv l\pmod{2m}$. (2) Suppose $w\ge1$. The first iteration ends with $w'=0$, without failure, if and only if $2^sw+s=J+1=K$ for the least admissible $s$. Conversely, if $2^\sigma w+\sigma=K$ for some $\sigma\ge1$, then $\sigma$ is the least admissible value, because $2^{\sigma-1}w+\sigma-1=(K+\sigma-2)/2\sigma$. Hence one-iteration success is equivalent to the existence of $s\ge1$ with $2^s(2^h-K)+s=K$, that is $K(2^s+1)=2^{h+s}+s$, which requires $2^{h+s}+s\equiv0$, that is $2^h\equiv s\pmod{2^s+1}$. Apply the fact with $m=s$: $s<2^s+1$, and $s=2^s+1-2^l$ with $l\le s-1$ would give $s\ge2^{s-1}+1>s$; hence $s=2^l$ for some $l$, which we call $k$, with $k\le s-1$, and $2^h\equiv2^k$ gives $h\equiv k\pmod{2^{k+1}}$. Moreover $w\ge1$ means $K<2^h$, which is $s<2^h$, that is $h>k$; with $h\equiv k\pmod{2^{k+1}}$ this gives $h\ge k+2^{k+1}\ge k+2$. Conversely, under these conditions Theorem~\ref{thm:members}(2) gives $K(2^s+1)=2^{h+s}+s$ with $1\le w$. (3) Suppose $w\ge1$. By Theorem~\ref{thm:step}, the first iteration fails if and only if $2^{s-1}w+s=J+1=K$ for the least admissible $s$, and then $s\ge2$. Conversely, if $2^{\sigma-1}w+\sigma=K$ for some $\sigma\ge2$, the proof of Theorem~\ref{thm:nonmembers} shows that $\sigma$ is the least admissible value. Hence first-iteration failure is equivalent to the existence of $s\ge2$ with $K(2^{s-1}+1)=2^{h+s-1}+s$, which requires $2^h\equiv s\pmod M$, $M=2^{s-1}+1$, and $w\ge1$ is $s<2^h$. Apply the fact with $m=s-1$; note $2\le s\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))<\infty$, the sum over $i$ is at least $\frac E2H-O(\log H)$. Theorem~\ref{thm:nonmembers}(2) gives the integers $3\le h\le H$ with $h\equiv3\pmod4$, at least $H/4-1$ of them. Hence $B(x)\ge(1+\frac14+\frac E2)H-O(\log H)$, and $H=\log_2x+O(1)$. \end{proof} \section{Successful states} \label{sec:states} For $J\ge1$ let \[ S_J=\{w:\ 0\le w\le J-1,\ 2^{J+1}w\in\mathcal{E}_J\},\qquad N(J)=|S_J|, \] so that $S_J$ is the set of $w$ for which the state $(J,w)$ of Section~\ref{sec:recursion} is successful. By Theorems~\ref{thm:equiv} and~\ref{thm:leading}, an exponent $a$ with candidate $K$ and $h=h(K)$ belongs to $\mathcal{A}$ if and only if $2^h-K\in S_{K-1}$. \begin{Proposition} \label{prop:Ncount} \begin{enumerate} \item For $J\ge1$, $N(J)=\#\{T\subseteq\{1,\dots,J\}:\ \sum_{j\in T}j2^j\equiv0\pmod{2^{J+1}}\}$. \item For $h\ge1$, the number of $a\in\mathcal{A}$ whose candidate $K$ lies in $(2^{h-1},2^h]$ equals $\#\{K\in(2^{h-1},2^h]:\ 2^h-K\in S_{K-1}\}$. \end{enumerate} \end{Proposition} \begin{proof} (1) By Lemma~\ref{lem:greedy}, the map $T\mapsto\sum_{j\in T}j2^j$ is injective on the subsets of $\{1,\dots,J\}$. If $\sum_{j\in T}j2^j\equiv0\pmod{2^{J+1}}$, the sum equals $2^{J+1}w$ with $w\ge0$, and $2^{J+1}w\le(J-1)2^{J+1}+2$ by Lemma~\ref{lem:sum}, so $w\le J-1$ and $w\in S_J$; conversely every $w\in S_J$ is obtained from exactly one $T$. (2) The map $K\mapsto\beta(K)-3$ is injective (Theorem~\ref{thm:leading}), and $\beta(K)-3\in\mathcal{A}$ if and only if $2^{h}-K\in S_{K-1}$. \end{proof} \begin{Proposition} \label{prop:symmetry} For every $J\ge1$, $w\in S_J$ if and only if $J-1-w\in S_J$. \end{Proposition} \begin{proof} For $J=1$, $S_1=\{0\}$. Let $J\ge2$, $w\in S_J$, and let $T\subseteq\{1,\dots,J\}$ represent $V=2^{J+1}w$. Since $J+1\ge3$, $V\equiv0\pmod8$, and as in the proof of Theorem~\ref{thm:equiv}, $1\notin T$. By Lemma~\ref{lem:sum}, $\sum_{j=2}^{J}j2^j=(J-1)2^{J+1}$, so the set $\{2,\dots,J\}\setminus T$ represents $(J-1)2^{J+1}-2^{J+1}w=2^{J+1}(J-1-w)$, and $J-1-w\in S_J$. Applying this to $J-1-w$ gives the converse. \end{proof} \begin{Proposition} \label{prop:Npairs} For every $k\ge1$, $N(2k+1)=N(2k)$, and $4\mid N(J)$ for every $J\ge4$. \end{Proposition} \begin{proof} Let $k\ge1$. For $T\subseteq\{1,\dots,2k+1\}$ put $U=T\setminus\{2k+1\}$ and $\sigma_U=\sum_{j\in U}j2^j$. Since $(2k+1)2^{2k+1}\equiv2^{2k+1}\pmod{2^{2k+2}}$, the condition $\sum_{j\in T}j2^j\equiv0\pmod{2^{2k+2}}$ is $\sigma_U\equiv-[2k+1\in T]\,2^{2k+1}\pmod{2^{2k+2}}$. If $\sigma_U\equiv0\pmod{2^{2k+1}}$, then $\sigma_U$ is congruent to $0$ or to $2^{2k+1}$ modulo $2^{2k+2}$, and exactly one of the two choices for $2k+1\in T$ satisfies the condition; otherwise none does. By Proposition~\ref{prop:Ncount}(1), $N(2k+1)=\#\{U\subseteq\{1,\dots,2k\}:\ \sigma_U\equiv0\pmod{2^{2k+1}}\}=N(2k)$. Let $k\ge2$. Since $2k\cdot2^{2k}=k2^{2k+1}\equiv0\pmod{2^{2k+1}}$, the element $2k$ does not affect the condition of Proposition~\ref{prop:Ncount}(1) for $J=2k$, so $N(2k)=2Z$ with $Z=\#\{U\subseteq\{1,\dots,2k-1\}:\ \sigma_U\equiv0\pmod{2^{2k+1}}\}$. For such $U$, $1\notin U$, because $2k+1\ge5$ and $\sigma_U\equiv2\pmod8$ when $1\in U$. By Lemma~\ref{lem:sum}, $\sum_{j=2}^{2k-1}j2^j=(2k-2)2^{2k}=(k-1)2^{2k+1}\equiv0\pmod{2^{2k+1}}$, so $U\mapsto\{2,\dots,2k-1\}\setminus U$ maps the sets counted by $Z$ to themselves; it is an involution without fixed points because $\{2,\dots,2k-1\}\neq\emptyset$. Hence $Z$ is even and $4\mid N(2k)$; with $N(2k+1)=N(2k)$ this gives $4\mid N(J)$ for all $J\ge4$. \end{proof} The recursion of Theorem~\ref{thm:step} organizes all states into a forest. For a state $(J,w)$ with $w\ge1$ that does not fail, let $\Phi(J,w)=(J-s,\,2^sw+s-J-1)$, with $s$ as in Theorem~\ref{thm:step}; by that theorem, $\Phi(J,w)$ is a state. We call $(J,w)$ a \emph{root} if $w=0$ or if $(J,w)$ fails. For $J\ge1$ let $F(J)$ be the number of states $(J,w)$ that fail. \begin{Theorem} \label{thm:forest} \begin{enumerate} \item A state $(J,w)$ with $w\ge1$ fails if and only if $w=(J+1-\sigma)/2^{\sigma-1}$ for some integer $\sigma\ge2$ with $2^{\sigma-1}\mid J+1-\sigma$ and $J+1-\sigma\ge2^{\sigma-1}$. Distinct $\sigma$ give distinct $w$, so $F(J)$ is the number of such $\sigma$, and for every $L\ge1$, \[ \sum_{J=1}^{L}F(J)=\sum_{\sigma=2}^{L}\Bigl\lfloor\frac{L+1-\sigma}{2^{\sigma-1}}\Bigr\rfloor. \] \item Let $(J',w')$ be a state and $m=v_2(J'+1+w')$. The states $(J,w)$ with $w\ge1$ that do not fail and satisfy $\Phi(J,w)=(J',w')$ are exactly the $m$ states $\bigl(J'+\sigma,\,(J'+1+w')/2^{\sigma}\bigr)$, $1\le\sigma\le m$. \item The map $\Phi$ makes the set of states a forest whose roots are the states $(J,0)$, $J\ge1$, and the failing states; a state is successful if and only if the root of its tree is a state $(J,0)$. For every $J\ge2$, \[ N(J)=1+\sum_{\sigma=1}^{J-1}\#\bigl\{w'\in S_{J-\sigma}:\ 2^{\sigma}\mid J-\sigma+1+w'\bigr\},\qquad J=1+F(J)+\sum_{\sigma=1}^{J-1}\#\bigl\{0\le w'\le J-\sigma-1:\ 2^{\sigma}\mid J-\sigma+1+w'\bigr\}. \] \item The initial states $(K-1,2^h-K)$, $K\in(2^{h-1},2^h]$, are exactly the states $(J,w)$ with $J+1+w=2^h$. \end{enumerate} \end{Theorem} \begin{proof} (1) By Theorem~\ref{thm:step}, $(J,w)$ fails if and only if $2^{s-1}w+s=J+1$ for the least admissible $s$. Conversely, suppose $2^{\sigma-1}w+\sigma=J+1$ for some $\sigma\ge2$. The function $\tau\mapsto2^\tau w+\tau$ is increasing; at $\tau=\sigma-1$ its value is $J\sigma$. Hence $\sigma$ is the least admissible value and the state fails. Therefore $(J,w)$ with $w\ge1$ fails if and only if $w=(J+1-\sigma)/2^{\sigma-1}$ for some $\sigma\ge2$, this quotient being an integer at least $1$; such a $w$ satisfies $w\le(J-1)/2\le J-1$, so $(J,w)$ is a state. The quotient is strictly decreasing in $\sigma$, so distinct $\sigma$ give distinct $w$. Finally, for fixed $\sigma\ge2$, the integers $J\le L$ with $J+1-\sigma=2^{\sigma-1}t$, $t\ge1$, correspond to $1\le t\le(L+1-\sigma)/2^{\sigma-1}$, and there are none when $\sigma>L$; summing over $\sigma$ gives the formula. (2) Put $u=J'+1+w'$; since $0\le w'\le J'-1$, $J'+1\le u\le2J'$. If $\Phi(J,w)=(J',w')$ with step $s$, then $J=J'+s$ and $2^sw=w'+J+1-s=u$, so $2^s\mid u$, $s\le m$ and $w=u/2^s$. Conversely, let $1\le\sigma\le m$, $J=J'+\sigma$ and $w=u/2^\sigma$. Then $w\ge1$, and $w\le u/2\le J'\le J-1$, so $(J,w)$ is a state. We have $2^\sigma w+\sigma=u+\sigma=J+1+w'\ge J+1$, and $2^{\sigma-1}w+\sigma-1=u/2+\sigma-1M+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$. Hence, for $h\ge4$, all the integers $K$ produced in the block $(2^{h-1},2^h]$ are distinct. Members. Besides the $2H-\log_2H-3$ exponents of the proof of Theorem~\ref{thm:counting}, Theorem~\ref{thm:symfamilies}(1) gives one exponent for each $4\le h\le H$, and Theorem~\ref{thm:symfamilies}(2) gives, for each $1\le i\le\kappa=\lfloor\log_2H\rfloor$, at least $(H-\sigma-1)/(\sigma+1)-1$ integers $h\in[\sigma+2,H]$ with $h\equiv i\pmod{\sigma+1}$, where $\sigma=2^{i-1}+1$. Since $\sum_{i>\kappa}1/(2^{i-1}+2)\le2^{1-\kappa}<4/H$ and $\sigma\le H/2+1$ for $i\le\kappa$, the sum over $i$ is at least $C_1H-O(\log H)$. Non-members. Besides the exponents of the proof of Theorem~\ref{thm:counting}, Theorem~\ref{thm:symfamilies}(3) gives, for each $2\le i\le\kappa$, at least $(H-\sigma)/\sigma-1$ integers $h\in[\sigma+1,H]$ with $h\equiv i\pmod\sigma$; as above, the sum over $i$ is at least $\bigl(\sum_{i\ge2}1/(2^{i-1}+1)\bigr)H-O(\log H)=C_2H-O(\log H)$. Since $H=\log_2x+O(1)$, the bounds follow. \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} By the proof of Theorem~\ref{thm:primes}(3), $u\le p^g\le p(u-1)$, $d=\lfloor p^g/u\rfloor\in[1,p-1]$ and $0\le w_0=p^g-du(p-1)K=u-p$ if and only if $w_0=u-j$ with $1\le j\le p-1$, that is $p^g+j=(d+1)u$, which is $u\mid p^g+j$ because $0\le w_0u-p$. For $p=3$, $e=2$ and $j\in\{1,2\}$; $2\mid3^g+j$ forces $j=1$, and $u=(3^g+1)/2$ is odd, that is $u\equiv1\pmod2$, exactly when $3^g\equiv1\pmod4$, that is $g$ even; this is Theorem~\ref{thm:primefamilies}(3). For given $g$, each pair $(e,j)$ gives at most one $u$, hence at most one exponent. \end{proof} The sets of successful $p$-states satisfy the analogues of Proposition~\ref{prop:symmetry} and Theorem~\ref{thm:bottomup}. For $K\ge0$ let $S^{(p)}_K$ be the set of $w$ such that $(K,w)$ is a successful $p$-state, and $N_p(K)=|S^{(p)}_K|$; let $u_K=(p-1)K+p$. \begin{Theorem} \label{thm:primebottomup} \begin{enumerate} \item $S^{(p)}_0=\{0\}$, and for every $K\ge0$, $S^{(p)}_{K+1}=\{(w+du_K)/p:\ w\in S^{(p)}_K,\ 0\le d\le p-1,\ p\mid w+du_K\}$, the elements obtained from distinct pairs $(w,d)$ being distinct. \item If $p\nmid K$, then for each $w\in S^{(p)}_K$ exactly one $d\in\{0,\dots,p-1\}$ satisfies $p\mid w+du_K$, and $N_p(K+1)=N_p(K)$. \item If $p\mid K$, then $S^{(p)}_{K+1}=\bigcup_{d=0}^{p-1}\bigl(B+d\,u_K/p\bigr)$ with $B=\{w/p:\ w\in S^{(p)}_K,\ p\mid w\}$, the $p$ sets being disjoint; thus $N_p(K+1)=p\,\#\{w\in S^{(p)}_K:\ p\mid w\}$. \item For every $K\ge0$, $w\in S^{(p)}_K$ if and only if $(p-1)K-w\in S^{(p)}_K$. \end{enumerate} An exponent $a$ with candidate $K$ belongs to $\mathcal{A}_p$ if and only if $w_0\le(p-1)K$ and $w_0\in S^{(p)}_K$, with $w_0$ as in Theorem~\ref{thm:primestep}(1). \end{Theorem} \begin{proof} (1) $\mathcal{E}^{(p)}_0=\{0\}$ gives $S^{(p)}_0=\{0\}$. By Theorem~\ref{thm:primes}(2), $p^{K+1}w'\in\mathcal{E}^{(p)}_{K+1}$ if and only if $p^{K+1}w'=dt_K+p^Kw$ with $0\le d\le p-1$ and $p^Kw\in\mathcal{E}^{(p)}_K$; since $t_K=p^Ku_K$, this is $pw'=w+du_K$, and $0\le w\le(p-1)K$ holds for every element $p^Kw$ of $\mathcal{E}^{(p)}_K$. Distinct pairs $(w,d)$ give distinct representations, hence distinct $w'$ by Theorem~\ref{thm:primes}(2). (2) $u_K\equiv(p-1)K\equiv-K\pmod p$ is invertible modulo $p$ when $p\nmid K$. (3) If $p\mid K$, then $p\mid u_K$, and $p\mid w+du_K$ is $p\mid w$ for all $d$; the sets are disjoint because $B\subseteq[0,(p-1)K/p]$ and $u_K/p=(p-1)K/p+1$. (4) By Lemma~\ref{lem:cp}(2), $\sum_{ip-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(3000)/3000$ & $0.7723$ & $0.5587$ & $0.6040$ & $0.4447$\\ \midrule no candidate & $7$ & $5$ & $5$ & $4$\\ immediate failure & $4$ & $7$ & $6$ & $10$\\ digit $d>p-1$ & $343$ & $197$ & $222$ & $125$\\ remainder $w'>(p-1)i$ & $330$ & $1116$ & $956$ & $1528$\\ success & $2317$ & $1676$ & $1812$ & $1334$\\ \bottomrule \end{tabular} \end{table} For $p=3$ the $4$ immediate failures up to $3000$ 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$ for $g=2,\dots,7$ when $p=3$; $0.4000,0.6400,0.5200,0.3952$ for $g=2,\dots,5$ 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\le10000$ with Theorem~\ref{thm:primebottomup}, in less than $3$ seconds for each prime. For every $K\le10000$ 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\le10000$. 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$ for $p=5$ and $g=5$ for $p=7$, the two numbers differ by at most $0.0110$. \begin{table}[H] \centering \caption{The counting functions $A_p(x)$ for $x\le10000$, 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$\\ \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$ & $4$ & $125$ & $0.5200$ & $0.5304$\\ $3$ & $6$ & $243$ & $0.6626$ & $0.6559$ & $5$ & $5$ & $625$ & $0.3952$ & $0.4173$\\ $3$ & $7$ & $729$ & $0.7586$ & $0.7565$ & $5$ & $6$ & $3125$ & $0.6474$ & $0.6513$\\ $3$ & $8$ & $2187$ & $0.7796$ & $0.7686$ & $7$ & $4$ & $343$ & $0.4052$ & $0.4243$\\ $3$ & $9$ & $6561$ & $0.6033$ & $0.6005$ & $7$ & $5$ & $2401$ & $0.6318$ & $0.6319$\\ & & & & & $11$ & $4$ & $1331$ & $0.3681$ & $0.3926$\\ \bottomrule \end{tabular} \end{table} For $x=1000,2000,\dots,10000$, the ratio $A_p(x)/x$ takes values between $0.6518$ and $0.7773$ for $p=3$, between $0.3970$ and $0.6132$ for $p=5$, between $0.5560$ and $0.6244$ for $p=7$, and between $0.3970$ and $0.4486$ for $p=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\le131000$, and $A(x)/x$ lies between $0.5132$ and $0.8750$ for $x=1000,2000,\dots,131000$. 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 131072 --pxmax 3000 --primes 3,5,7,11 --kmax 10000}, using Python~3.12.3 and NumPy~2.4.6. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \bibliographystyle{elsarticle-num} \bibliography{biblio} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \end{document}