1 Introduction

Let \(\mathbb {N}\) be the set of non-negative integers and \(\mathbb {N}_{+}\) the set of positive integers. Moreover, for a given \(n\in \mathbb {Z}\) we define the 2-adic valuation of n as

$$\begin{aligned} \nu _{2}(n)=\max \{k\in \mathbb {N}:\;2^{k}|n\}, \end{aligned}$$

with the convention that \(\nu _{2}(0)=+\infty \).

The problem of representation of integers by quadratic forms or, more generally, by forms or polynomials in many variables, is a classical one. As was proved by Lagrange in 1770, each non-negative integer can be represented as a sum of four squares. On the other hand, there are infinitely many positive integers which cannot be represented by three squares. More precisely, in 1798 Legendre proved that a non-negative integer N can be represented as

$$\begin{aligned} N=x^2+y^2+z^2 \end{aligned}$$

for some \(x, y, z\in \mathbb {Z}\) if and only if N is not of the form \(4^{r}(8s+7)\) for \(r, s\in \mathbb {N}\). In particular, the natural density of the set of integers that cannot be represented by a sum of three squares is equal to 1/6. This raises an interesting question whether for a given sequence of integers \((u_{n})_{n\in \mathbb {N}}\) there exist infinitely many solutions of the Diophantine equation

$$\begin{aligned} u_{n}=x^2+y^2+z^2. \end{aligned}$$
(1)

To characterize the solutions of (1) it is necessary to have a good understanding of the 2-adic behavior, or, to be more precise, the 2-adic valuation of the terms of the sequence \((u_{n})_{n\in \mathbb {N}}\).

Especially interesting is the case where \(u_{n}\) has a combinatorial meaning, i.e., \(u_{n}\) counts some discrete objects or structures. Equation (1) with \(u_{n}=\left( {\begin{array}{c}2n\\ n\end{array}}\right) \) was investigated by Granville and Zhu in [9]. They characterized those \(n\in \mathbb {N}\) such that (1) has no solutions in xyz. In particular, the set of integers n, for which \(\left( {\begin{array}{c}2n\\ n\end{array}}\right) \) can be represented as a sum of three squares, has asymptotic density 7/8 in the set of all natural numbers (for an early study of this problem, see also the paper of Robbins [20]). In the same paper they also obtained a characterization of \(n \in \mathbb {N}\) such that n! is not a sum of three squares, given in terms of the existence of certain patterns in the binary expansion of n. A different approach to this problem (via substitutions) was presented by Deshouillers and Luca [8]. They showed that the natural density of n such that \(n!=x^2+y^2+z^2\) exists and is equal to 7/8. More precisely, they proved that

$$\begin{aligned} \#\{n\le x:\;n!\;\text{ is } \text{ a } \text{ sum } \text{ of } \text{ three } \text{ squares }\}=\frac{7}{8}x+O(r(x)), \end{aligned}$$

where \(r(x)=x^{2/3}\). The error term was improved by Hajdu and Papp [15] to \(r(x)=x^{1/2}\log ^{2}x\), and recently by Burns to \(r(x)=x^{1/2}\) (see the preprint [6]). On the other hand, Robbins obtained a precise characterization of the solutions in n of (1) in the case where \(u_{n}\) is the nth term of Fibonacci or Lucas sequence [19].

In this paper, we follow the same line of research and consider, in particular, Eq. (1) with \(u_{n}\) being the binary partition function b(n) (sequence A018819 in the OEIS [18]). More precisely, b(n) counts the number of partitions of \(n \in \mathbb {N}\) into parts being powers of two. For example, \(b(4)=4\) because

$$\begin{aligned} 4=2^2=2+2=1+1+2=1+1+1+1 \end{aligned}$$

are all possible representations of 4 as a sum of powers of 2. The sequence \((b(n))_{n\in \mathbb {N}}\) was already introduced by Euler. However, it seems that the first serious study of its properties was performed by Churchhouse [7] in 1969, who computed the 2-adic valuation of b(n). Further results, motivated by Churchhouse’s computations, were obtained independently by Gupta [11,12,13] and Rødseth [21] (see also recent studies by Rødseth and Sellers [22]).

Besides being interesting in its own sake, the study of the equation

$$\begin{aligned} b(n)=x^2+y^2+z^2 \end{aligned}$$

connects two different areas: Diophantine equations and partition theory. According to our best knowledge, there is no result in the literature providing a characterization of the solutions of Eq. (1) with \(u_{n}\) being a partition function of sub-exponential growth. Recall that b(n) is indeed of sub-exponential growth. More precisely, Mahler [16] proved that \(\log _{2} b(n)\sim \frac{1}{2}(\log _{2} n)^{2}\). Our study can be seen as a continuation and extension of recent research concerning solvability of Diophantine equations involving partitions, conducted by Tengely and Ulas [25].

In the same context, we also study the m-colored binary partition function \(b_m(n)\), which counts binary partitions of n, where each part can have one of \(m \ge 1\) colors. In particular, we have \(b(n) = b_1(n)\). The study of arithmetic properties of this function was initiated in a paper of Gawron et al. [10], where several useful results were obtained.

Let us describe the content of the paper in some more detail. In Sect. 2 we recall some basic properties and results concerning the function \(b_m(n)\). The main goal of the present investigation, pursued in Sects. 35, is to obtain an explicit characterization of the set

$$\begin{aligned} S_m = \{n \in \mathbb {N}: b_m(n) \ne x^2+y^2+z^2 \text { for any } x,y,z \in \mathbb {Z}\}. \end{aligned}$$

The reason for considering terms not represented as a sum of three squares is that the description turns out to be more concise (similarly as for non-negative integers). We focus primarily on the case \(m=2^k-1\) for \(k \in \mathbb {N}_+\) due to the fact that the 2-adic valuation \(\nu _2(b_{2^k-1}(n))\) is known to be bounded [7, 10]. This allows us to determine which terms \(b_{2^k-1}(n)\) are of the form \(4^{r}(8s+7)\) through the reduction modulo a suitable power of 2. The analysis is divided into three cases: \(k=1, k=2\), and \(k \ge 3\), covered in Sects. 3, 4, and 5, respectively. Based on these results, in Sect. 6 we give quite precise bounds for the counting function of the set \(S_{2^k-1}\), and determine its natural density in the process. In the final section, we state some questions, problems, and conjectures which may serve as a basis for further study. In particular, we discuss the equation \(b_m(n) = x^2+y^2+z^2\) when \(m \ne 2^k-1\) as well as some interesting findings concerning the behavior of \(b_m(n)\) modulo powers of 2. We also collect results of numerical computations related to the equations \(b(n)=x^2+y^2+z^4\) and \(b(n)=x^2+y^2\).

Remark 1.1

In this paper, we focus on the problem of representation of \(b_{2^{k}-1}(n)\) as a sum of three squares. However, it is possible to use our findings to obtain similar results for other ternary quadratic forms q such that the set of \(n \in \mathbb {N}\) represented by q is given in terms of the binary expansion of n. Such quadratic forms include \(x^2 + y^2 + 2z^2, x^2 + 2y^2 + 2z^2, x^2 + 2y^2 + 4z^2\), etc.

2 Preliminaries

In this section we collect known properties and results which will be used throughout the paper. Recall that the ordinary generating function of the sequence \((b(n))_{n\in \mathbb {N}}\) has the form

$$\begin{aligned} B(x)=\prod _{n=0}^{\infty }\frac{1}{1-x^{2^{n}}}=\sum _{n=0}^{\infty }b(n)x^{n}. \end{aligned}$$

As a consequence, we see that B(x) satisfies a Mahler-type functional equation \((1-x)B(x)=B(x^2)\). Comparing the coefficients on both sides, we see that the sequence \((b(n))_{n\in \mathbb {N}}\) satisfies the recurrence: \(b(0)=b(1)=1\) and

$$\begin{aligned} b(2n)=b(2n-1)+b(n),\quad b(2n+1)=b(2n). \end{aligned}$$

Churchouse [7] obtained a characterization of the 2-adic valuation of the terms b(n).

Theorem 2.1

For all \(n \ge 2\) we have

$$\begin{aligned} \nu _2(b(n)) = {\left\{ \begin{array}{ll} 2 &{}\quad \text {if }n=4^{m}(2k+1)+i\;\text {for some}\;m\in \mathbb {N}_{+}, k\in \mathbb {N}, i\in \{0,1\}, \\ 1 &{}\quad \text {otherwise}. \end{array}\right. } \end{aligned}$$

Another useful result was obtained independently by Rødseth [21] and Gupta [11], proving a conjecture of Churchhouse. More precisely, we have the following theorem.

Theorem 2.2

For all \(s \in \mathbb {N}\) and odd \(n\in \mathbb {N}\) the following congruence holds:

$$\begin{aligned} b(2^{s+2}n)\equiv b(2^{s}n)\pmod {2^{\mu (s)}}, \end{aligned}$$

where \(\mu (s)=\left\lfloor \frac{3s+4}{2}\right\rfloor \).

For \(m\in \mathbb {N}_{+}\) we define the sequence \((b_{m}(n))_{n \in \mathbb {N}}\) as the convolution of m copies of \((b(n))_{n \in \mathbb {N}}\). More precisely,

$$\begin{aligned} b_{m}(n)=\sum _{i_{1}+\ldots +i_{m}=n}b(i_{1})\cdots b(i_{m}). \end{aligned}$$

It is clear that the generating function \(B_m(x)\) of the sequence \((b_{m}(n))_{n\in \mathbb {N}}\) is the mth power of B(x), and \(b_{m}(n)\) also has a combinatorial interpretation. Indeed, \(b_{m}(n)\) is the number of binary partitions of n, where each part has one of m possible colors. In a recent paper by Gawron et al. [10], it is proved that for \(m=2^{k}-1\) and \(n\ge 2^{k}\) the 2-adic valuation of \(b_{m}(n)\) belongs to the set \(\{1,2\}\). More precisely, they gave the following characterization of the 2-adic valuation of the terms \(b_{2^k-1}(n)\).

Theorem 2.3

(Theorem 4.6 in [10]). Let \(k \in \mathbb {N}_{+}\). For \(n,i \in \mathbb {N}\) such that \(i < 2^{k+2}\) we have

$$\begin{aligned} \nu _2(b_{2^k-1}(2^{k+2}n+i)) = {\left\{ \begin{array}{ll} \nu _2(b(8n)) &{}\quad \text {if } 0 \le i< 2^k, \\ 1 &{}\quad \text {if } 2^k \le i< 2^{k+1}, \\ 2 &{}\quad \text {if } 2^{k+1} \le i< 3 \cdot 2^{k}, \\ 1 &{}\quad \text {if } 3 \cdot 2^{k} \le i < 2^{k+2}. \end{array}\right. } \end{aligned}$$

In particular, \(\nu _2(b_{2^k-1}(n)) \in \{0,1,2\}\) and \(\nu _2(b_{2^k-1}(n)) = 0\) if and only if \(n < 2^k\).

The reciprocal of B(x), denoted by

$$\begin{aligned} T(x)=\frac{1}{B(x)}=\prod _{n=0}^{\infty }\left( 1-x^{2^{n}}\right) =\sum _{n=0}^{\infty }t_{n}x^{n}, \end{aligned}$$

is the ordinary generating function for the famous Prouhet–Thue–Morse sequence \((t_{n})_{n\in \mathbb {N}}\) (PTM sequence for short). Recall that \(t_{n}=(-1)^{s_{2}(n)}\), where \(s_{2}(n)\) is the number of 1’s in the unique expansion of n in base 2. Equivalently, we have \(t_{0}=1\) and

$$\begin{aligned} t_{2n}=t_{n},\quad t_{2n+1}=-t_{n},\quad n\ge 0. \end{aligned}$$

The formula in Theorem 2.1 can then be written as \( \nu _{2}(b(n))=\frac{1}{2}|t_{n}-2t_{n-1}+t_{n-2}|\). We also consider a variant of the PTM sequence, given by

$$\begin{aligned} T_{n}=s_{2}(n)\bmod {2}, \end{aligned}$$

i.e., the sequence \((T_{n})_{n\in \mathbb {N}}\) is related to the PTM sequence by \(t_{n}=1-2T_{n}\).

The PTM sequence is an example of an automatic sequence. More precisely, let \(k \ge 2\) be a fixed integer. A sequence \({\textbf{a}} = (a_n)_{n\in \mathbb {N}}\) is called k-automatic if its k-kernel, namely

$$\begin{aligned} K_k({\textbf{a}}) = \{(a_{k^jn+i})_{n\in \mathbb {N}}: j \in \mathbb {N}, 0 \le i < k^j \}, \end{aligned}$$

is a finite set. Equivalently, \({\textbf{a}}\) is k-automatic if there exists a deterministic finite automaton with output (DFAO) that reads the canonical base-k representation of n and the outputs \(a_n\). In the case of the PTM sequence, it is clear that \(K_k({\textbf{t}}) =\{{\textbf{t}}, -{\textbf{t}}\}\). Equivalently, the sequence is generated by the DFAO in Fig. 1. To generate \(t_n\), one moves between the states (symbolized by nodes) according to subsequent digits in the binary representation of n. After the final digit has been read, the DFAO returns the output corresponding to the current state. For a detailed treatment of automatic sequences, we refer the reader to the monograph by Allouche and Shallit [3].

Fig. 1
figure 1

A DFAO generating the PTM sequence

Finally, when a sequence \(\textbf{a}\) takes values in a \(\mathbb {Z}\)-module R, it is called k-regular if there exist finitely many sequences \({\textbf{a}}_{i} = (a_i(n))_{n\in \mathbb {N}}\) with values in R such that each sequence in \(K_k(\textbf{a})\) is a \(\mathbb {Z}\)-linear combination of the \(\textbf{a}_{i}\). In other words, the \(\mathbb {Z}\)-submodule generated by the k-kernel \(K_k(\textbf{a})\) is finitely generated. In particular, k-automatic sequences are precisely k-regular sequences taking finitely many values. The class of k-regular sequences with values in a ring R has a ring structure itself. A good introduction to the topic of regular sequences are the papers of Allouche and Shallit [4, 5].

3 The Equation \(b(n)=x^2+y^2+z^2\)

We start with the characterization of the solutions (in variable n) of the equation

$$\begin{aligned} b(n)=x^2+y^2+z^2. \end{aligned}$$

Because the values b(2n) and \(b(2n+1)\) are equal, we restrict our attention to even indices and consider the set

$$\begin{aligned} S_1'=\{ n \in \mathbb {N}: b(2n)\ne x^2+y^2+z^2 \text { for any } x,y,z \in \mathbb {Z}\}. \end{aligned}$$

The first few elements of \(S_1'\) are the following:

$$\begin{aligned} 10, 18, 34, 40, 58, 66, 72, 90, 106, 114, 130, 136, 154, 160, 170, 178, 202, 210, 226, \ldots . \end{aligned}$$

Using Theorem 2.1, we get the following characterization of \(\nu _2(b(2n))\).

Proposition 3.1

For all \(n \in \mathbb {N}_+\) we have

$$\begin{aligned} \nu _2(b(2n)) = {\left\{ \begin{array}{ll} 1 &{}\quad \text {if } \nu _2(n) \equiv 0 \pmod {2}, \\ 2 &{}\quad \text {if } \nu _2(n) \equiv 1 \pmod {2}. \end{array}\right. } \end{aligned}$$

We can deduce that if \(\nu _2(n) \equiv 0 \pmod {2}\), then b(2n) is a sum of three squares. Hence, we only need to consider reduction modulo 32 of \(b(4^k(8m+4))\), where \(k,m \in \mathbb {N}\). More precisely, \(b(4^k(8m+4))\) is not a sum of three squares if and only if

$$\begin{aligned} b(4^k(8m+4)) \equiv 28 {\pmod {32}}. \end{aligned}$$
(2)

From Theorem 2.2 (applied to \(s=2\)) and the main result of Hirschhorn and Loxton [14] one can extract suitable congruence relations, which reduce the general case to \(k=0\) and describe the remaining terms \(b(8m+4)\).

Proposition 3.2

For all \(m \in \mathbb {N}\) we have

$$\begin{aligned} b(16m)&\equiv b(4m) \pmod {32}, \\ b(16m+4)&\equiv 4t_m \pmod {32}, \\ b(16m+12)&\equiv 20t_m \pmod {32}. \end{aligned}$$

Using these relations, it is straightforward to describe the set consisting of \(n \in \mathbb {N}\) such that b(2n) is (not) a sum of three squares.

Corollary 3.3

The following conditions are equivalent:

  1. (a)

    the number b(2n) is not a sum of three squares;

  2. (b)

    \(n = 2^{2k+1}(4s+1)\) for some \(k,s \in \mathbb {N}\) such that \(t_s = -1\);

  3. (c)

    \(n=2^{2k+1}(8r+2t_{r}+3)\) for some \(k,r \in \mathbb {N}\);

  4. (d)

    \(\chi (n) = 1\), where \(\chi \) is defined by \(\chi (0) = 0\) and

    $$\begin{aligned} \chi (2n+1)=0, \quad \chi (4n)=\chi (n), \quad \chi (8n+2)=T_n, \quad \chi (8n+6)=0. \end{aligned}$$

Proof

As we have discussed earlier, b(2n) is not a sum of three squares if and only if \(2n = 4^k(8m+4)\) and (2) holds. By Proposition 3.2 this happens if and only if m is even and \(t_m = t_{m/2} = -1\). Letting \(m = 2s\), we obtain the equivalence of (a) and (b).

To prove that (b) is equivalent to (c), we use the following description from [1]:

$$\begin{aligned} \{n\in \mathbb {N}:\;T_{n}=0\}&=\{2m+T_m:\;m\in \mathbb {N}\},\nonumber \\ \{n\in \mathbb {N}:\;T_{n}=1\}&=\{2m+1-T_{m}:\;m\in \mathbb {N}\}. \end{aligned}$$
(3)

Hence, \(t_s=-1\) if and only if \(s=2r+1-T_r = 2r+(t_r+1)/2\) for some \(r \in \mathbb {N}\), and our claim follows.

Finally, it is simple to check that the set on n of the form given in (b) is precisely \(\{n \in \mathbb {N}: \chi (n) = 1 \}\). \(\square \)

From the relation \(b(2n+1) = b(2n)\) and part (c) of the corollary we get

$$\begin{aligned} S_1 = 2S_1' \cup (2S_1' +1) = \{ 2^{2k+2} (8r+2t_r+3) +i: k,r \in \mathbb {N}, i \in \{0,1\}\}. \end{aligned}$$

Furthermore, part (d) of the corollary directly shows that \(S_1'\) (and thus \(S_1\)) is a 2-automatic set; i.e., its characteristic sequence \((\chi (n))_{n \in \mathbb {N}}\) is 2-automatic. A DFAO generating this sequence is shown in Fig. 2.

Fig. 2
figure 2

A DFAO generating \((\chi (n))_{n \in \mathbb {N}}\)

We now turn to the problem of gaps between consecutive n such that b(2n) is a sum of three squares. More precisely, we define \((f_n)_{n \in \mathbb {N}}\) to be the increasing sequence consisting of the elements of \(S_1'\). Let \((g_n)_{n \in \mathbb {N}}\) be the sequence of gaps, defined by

$$\begin{aligned} g_n = f_{n+1} - f_n. \end{aligned}$$

In other words, \(g_n\) is the distance between nth and \((n+1)\)th 1 in the characteristic sequence \((\chi (n))_{n \in \mathbb {N}}\) (counting from 0). The following proposition shows that the gaps are bounded. Moreover, for each possible gap length g we provide in the proof an infinite set of \(n \in \mathbb {N}\) such that \(g_n = g\).

Proposition 3.4

For all \(n \in \mathbb {N}\) we have

$$\begin{aligned} g_n \in \{6,8,10,16,18,24\} \end{aligned}$$

and all possible values are attained infinitely often.

Proof

Consider length 16 subsequences \((\chi (16n+i))_{0 \le i \le 15}\). A simple case distinction together with the relations in Corollary 3.3(d) show that there are only four possibilities, namely

$$\begin{aligned} {\left\{ \begin{array}{ll} 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0 &{}\quad \text {if } \chi (n) = 1, \\ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0 &{}\quad \text {if } \chi (n) = 0, T_n =1, \\ 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0 &{}\quad \text {if } \chi (n) = 0, T_n = 0, 2 \mid n, \\ 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 &{}\quad \text {if } \chi (n) = 0, T_n = 0, 2 \not \mid n. \\ \end{array}\right. } \end{aligned}$$

By inspecting the gaps within these subsequences and all their possible concatenations, we can see that the gaps between subsequent 1’s in \((\chi (n))_{n \in \mathbb {N}}\) can only have lengths 6, 8, 10, 16, 18, 24.

It remains to show that each of these values is indeed attained infinitely often. In Table 1 for each \(g \in \{6,8,10,16,18,24\}\) we provide an infinite set \(I_g\) of indices n such that \(\chi (n) = \chi (n+g) = 1\) and all the terms inbetween are zero. We note that \(I_g\) does not necessarily contain all such indices n. The verification of each case is straightforward and left to the reader. \(\square \)

Table 1 Gaps between 1’s in \((\chi (n))_{n \in \mathbb {N}}\)

Remark 3.5

Let us note that Hajdu and Papp proved that the gap sequence corresponding to those values of n such that n! is a sum of three squares is bounded by 42 [15, Theorem 2.4]. Moreover, in a recent paper [6], Burns provided the list of all possible lengths of gaps.

It is also interesting to ask whether the sequence \((f_n)_{n \in \mathbb {N}}\) itself is 2-regular (equivalently, \((g_n)_{n \in \mathbb {N}}\) is 2 automatic), since its values form a 2-automatic set. This question seems hard, and we have not been able to give a definitive answer (see also Sect. 7). The problem comes from the fact that the description of elements of \(S_1'\) in Corollary 3.3 does not give enough information about their ordering. Instead, we consider a simpler version of this question, where we restrict our attention to indices \(n \in S_1'\) with fixed 2-adic valuation. More precisely, we let \(k = 0\) in the description of Corollary 3.3, so that n is of the form \(4m+2\). Then b(2n) is not a sum of three squares if and only if \(b(8m+4) \equiv 28 \pmod {32}\) (this is precisely (2) with \(k=0\)). More generally, put

$$\begin{aligned} \beta (m) = \frac{b(8m+4)}{4} \bmod {8}, \end{aligned}$$

and for each \(a\in \{1,3, 5, 7\}\) let \(\textbf{c}_{a}=(c_{a}(l))_{l\in \mathbb {N}}\) be the increasing sequence such that

$$\begin{aligned} \{m\in \mathbb {N}:\;\beta (m)=a\}=\{c_{a}(l):\;l\in \mathbb {N}\}. \end{aligned}$$

It turns out that these sequences are described by surprisingly simple formulas.

Theorem 3.6

For each \(a\in \{1,3, 5, 7\}\) the sequence \(\textbf{c}_{a}\) is 2-regular. More precisely, for \(m \in \mathbb {N}\) we have

$$\begin{aligned} c_{1}(l)&=4l-t_{l}+1,\\ c_{3}(l)&=4l+t_{l}+2,\\ c_{5}(l)&=4l-t_{l}+2,\\ c_{7}(l)&=4l+t_{l}+1. \end{aligned}$$

Proof

It is easy to see that each of the sequences from the statement is increasing.

To prove that \(\beta (m)=a\) if and only if \(m=c_a(l)\) for some \(l \in \mathbb {N}\), we restate the second and third relation of Proposition 3.2 in the following way:

$$\begin{aligned} \beta (m) = {\left\{ \begin{array}{ll} 1 &{}\quad \text {if } 2 \mid m \text { and } t_m = 1, \\ 3 &{}\quad \text {if } 2 \not \mid m \text { and } t_m = 1, \\ 5 &{}\quad \text {if } 2 \not \mid m \text { and } t_m = -1, \\ 7 &{}\quad \text {if } 2 \mid m \text { and } t_m = -1. \\ \end{array}\right. } \end{aligned}$$

We now use the relations (3). If \(\beta (m)=1\), then \(2 \mid m\) and \(m=2k + T_k\) for some \(k \in \mathbb {N}\). This implies \(T_k=0\), and thus \(k=2l+T_l\) for some \(l \in \mathbb {N}\). As a result, we get \(m = 4l+2T_l= 4l-t_l+1\). Conversely, if m is of this form, then also \(\beta (m)=1\), and so we get the claim for \(a=1\).

The proof for \(a=3,5,7\) is similar. \(\square \)

To conclude this section, we point out that similar results can be obtained for other quadratic forms given in Remark 1.1. More precisely, depending on the chosen form, they can be derived from either Proposition 3.2 or the following set of congruence relations (which again follows from Hirschhorn and Loxton’s results).

Proposition 3.7

For all \(n \in \mathbb {N}\) we have

$$\begin{aligned} b(16n+8)&\equiv b(4n+2) \pmod {16}, \\ b(8n+2)&\equiv 2t_n \pmod {16}, \\ b(8n+6)&\equiv 6t_n \pmod {16}. \end{aligned}$$

4 The Equation \(b_3(n)=x^2+y^2+z^2\)

In this section we characterize the elements of the set \(S_{3}\) containing those n such that \(b_{3}(n)\) is not a sum of three squares. By virtue of Theorem 2.3, to get the required characterization of \(S_{3}\), we need to understand of the behaviour of \(b_{3}(16n+i)\mod 32\) for \(i=0, 1, 2, 3, 8, 9, 10, 11\). Let us recall that the sequence \((b_{3}(n))_{n\in \mathbb {N}}\) satisfies the following recurrence relations: \(b_{3}(0)=1, b_{3}(1)=3, b_{3}(2)=9\) and

$$\begin{aligned} b_{3}(2n)&=3b_{3}(2n-1)-3b_{3}(2n-2)+b_{3}(2n-3)+b_{3}(n),\\ b_{3}(2n+1)&=3b_{3}(2n)-3b_{3}(2n-1)+b_{3}(2n-2). \end{aligned}$$

We start with the following lemma.

Lemma 4.1

For all \(n \in \mathbb {N}\) the following congruences hold:

$$\begin{aligned} b_{3}(8n+i+4)&\equiv 2(2i+1+4(-1)^{n})t_{n}\pmod {32},\\ b_{3}(32n+i)&\equiv b_{3}(8n+i)\pmod {64},\;i=0, 1, 2, 3\\ b_{3}(8(2n+1)+i)&\equiv 4(3+3i-i^2-2(-1)^{n+i})t_{n}\pmod {32}\\&\equiv {\left\{ \begin{array}{ll} 4(3-2(-1)^n)t_{n}\pmod {32} &{}\quad \textrm{if }\, i=0, \\ 4(5+2(-1)^n)t_{n}\pmod {32} &{}\quad \textrm{if }\, i=1, \\ 4(5-2(-1)^n)t_{n}\pmod {32} &{}\quad \textrm{if }\, i=2, \\ 4(3+2(-1)^n)t_{n}\pmod {32} &{}\quad \textrm{if }\, i=3. \end{array}\right. } \end{aligned}$$

In particular, for each \(k\in \mathbb {N}_{+}\) and \(i\in \{0,1,2,3\}\), we have

$$\begin{aligned} b_{3}(2^{2k}(2n+1)+i)&\equiv 2\pmod {4},\\ b_{3}(2^{2k+1}(2n+1)+i)&\equiv b_{3}(8(2n+1)+i)\pmod {32}, \end{aligned}$$

Proof

The computation of the values of \(b_{3}(8n+i+4)\mod 32 \) and \(b_{3}(8(2n+1)+i)\mod 32 \) for \(i=0, 1, 2, 3\) is based on a simple induction with the help of recurrence relations satisfied by the PTM sequence \((t_{n})_{n\in \mathbb {N}}\) and the sequence \((b_{3}(n))_{n\in \mathbb {N}}\). Because of this, we omit the simple details. Essentially, the same approach can be used in the case of the congruence \(b_{3}(32n+i)\equiv b_{3}(8n+i)\pmod {32}\).

However, a more conceptual proof is the following. Invoking [10, Lemma 4.7] we know that for each \(a\in \mathbb {N}_{+}, b\in \{0, 1, \ldots , 2^{a}-1\}\) there is a polynomial \(P_{a,b}\in \mathbb {Z}[x]\) such that

$$\begin{aligned} \sum _{n=0}^{\infty }b_{3}(2^{a}n+b)x^{n}=\frac{P_{a,b}(x)}{(1-x)^{3a}}B_{3}(x). \end{aligned}$$

In particular, in the case we are interested in, we have

$$\begin{aligned} \sum _{n=0}^{\infty }(b_{3}(32n+i)-b_{3}(8n+i))x^{n}=\frac{P_{5,i}(x)-(1-x)^{6}P_{3,i}(x)}{(1-x)^{15}}B_{3}(x). \end{aligned}$$

A quick computation reveals that for each \(i=0, 1, 2, 3\), the polynomial \(P_{5,i}(x)-(1-x)^{6}P_{3,i}(x)\) is divisible by 64 in the ring \(\mathbb {Z}[x]\). Thus, as the function \((1-x)^{-15}B_{3}(x)\) has power series expansion with integer coefficients, then each number \(b_{3}(32n+i)-b_{3}(8n+i)\) is divisible by 64 and we are done.

To obtain the first congruence from the “in particular” part, we apply induction on k and the congruence \(b_{3}(8n+i+4)\equiv 2(2i+1+4(-1)^{n})t_{n}\pmod {32}\). The second congruence again follows from induction on k and the congruence \(b_{3}(32n+i)\equiv b_{3}(8n+i)\pmod {64}\). \(\square \)

We are ready to characterize the set \(S_{3}\).

Theorem 4.2

We have \(n\in S_{3}\) if and only if

$$\begin{aligned} n=2^{2k+1}\left( 8p+2\left\lfloor \frac{i}{2}\right\rfloor +3+2(-1)^{i}t_{p}\right) +i \end{aligned}$$

for some \(i\in \{0, 1, 2, 3\}\) and \(k \in \mathbb {N}_+\), \(p\in \mathbb {N}\).

Proof

From the characterization of the 2-adic valuation of \(b_{3}(n)\) and Lemma 4.1 we know that if \(n\in S_{3}\), then we necessarily have \(n\pmod {16}\in \{0, 1, 2, 3, 8, 9, 10, 11\}\). We perform a case-by-case analysis.

Let \(i\in \{0, 1, 2, 3\}\). If \(n\equiv i\pmod {16}\) and \(n=2^{2k}(2s+1)+i\), then \(\nu _{2}(b_{3}(n))=1\) and hence \(n\not \in S_{3}\). If \(n=2^{2k+1}(2s+1)+i\), then we have

$$\begin{aligned} b_{3}(n)\equiv b_{3}(8(2s+1)+i)\equiv 4(3+3i-i^2-2(-1)^{s+i})t_{s}\pmod {32}, \end{aligned}$$

and thus \(n\in S_{3}\) if and only if \(c(i,s):=(3+3i-i^2-2(-1)^{s+i})t_{s}\equiv 7\pmod {8}\). A case-by-case analysis using the characterization (3), reveals the following:

  1. (1)

    If \(i=0\), then \(c(i,s)\equiv 7\pmod {8}\) if and only if s is even and \(t_{s}=-1\). Thus, \(s=4p+1+t_{p}\) for some \(p\in \mathbb {N}\).

  2. (2)

    If \(i=1\), then \(c(i,s)\equiv 7\pmod {8}\) if and only if s is even and \(t_{s}=1\). Thus, \(s=4p+1-t_{p}\) for some \(p\in \mathbb {N}\).

  3. (3)

    If \(i=2\), then \(c(i,s)\equiv 7\pmod {8}\) if and only if s is odd, and \(t_{s}=1.\) Thus, \(s=4p+2+t_{p}\) for some \(p\in \mathbb {N}\).

  4. (4)

    If \(i=3\), then \(c(i,s)\equiv 7\pmod {8}\) if and only if s is odd and \(t_{s}=-1.\) Thus, \(s=4p+2-t_{p}\) for some \(p\in \mathbb {N}\).

Gathering all the obtained characterizations, we get the statement of our theorem. \(\square \)

Remark 4.3

In a similar fashion as in the case of b(n), one can compute possible gaps between n such that \(b_3(n)\) is not a sum of three squares. As pointed out by the referee, one can do this using the software Walnut written by Hamoon Mousavi [17]. For a broad range of examples and applications of Walnut see the recent book by Shallit [24].

More precisely, if s3 is the DFAO generating the characteristic sequence of \(S_3\) (obtained using the characterization of c(is)), then the Walnut command

figure a

produces a deterministic finite automaton (DFA) s3gaps accepting precisely those \(g\in \mathbb {N}_+\) which are lengths of the gaps. By inspecting the result, one can see that the gaps are \(g = 6,7,9,14,18\). Using the results from Sect. 5, the same can be done for \(b_{2^k-1}(n)\) with \(k \ge 3\).

5 The Equation \(b_{2^k-1}(n)=x^2+y^2+z^2\) with \(k \ge 3\)

In this section, we study for \(k \ge 3\) representability of \(b_{2^k-1}(n)\) as a sum of three squares. The main idea is to express \((b_{2^k-1}(n))_{n \in \mathbb {N}}\) as the convolution of \((b_{2^k}(n))_{n \in \mathbb {N}}\) and the PTM sequence, and apply the following lemma [10, Lemma 4.4(1)] to \(m=2^k\).

Lemma 5.1

Let \(m \in \mathbb {N}_+\). Then for all \(n \in \mathbb {N}\) we have

$$\begin{aligned} b_{m}(n) \equiv \left( {\begin{array}{c}m\\ n\end{array}}\right) + 2^{\nu _2(m)+1} \left( {\begin{array}{c}m-2\\ n-2\end{array}}\right) \pmod {2^{\nu _2(m)+2}}. \end{aligned}$$

We split our reasoning into two parts: \(n < 2^k\) and \(n \ge 2^k\). Starting with the simpler case \(n < 2^k\), by Theorem 2.3, we have \(\nu _2(b_{2^k-1}(n)) = 0\). Therefore, it is sufficient for our purposes to describe \(b_{2^k-1}(n)\) modulo 8.

Proposition 5.2

Let \(k \ge 3\) and \(n < 2^k\). Then

$$\begin{aligned} b_{2^k-1}(n) \equiv t_n \cdot {\left\{ \begin{array}{ll} 1 \pmod {8} &{}\text {if } 0 \le n< 2^{k-2}, \\ 5 \pmod {8} &{}\text {if } 2^{k-2} \le n< 2^{k-1},\\ 7 \pmod {8} &{}\text {if } 2^{k-1} \le n< 3 \cdot 2^{k-2},\\ 3 \pmod {8} &{}\text {if } 3 \cdot 2^{k-2} \le n < 2^{k}. \end{array}\right. } \end{aligned}$$

Proof

By Lemma 5.1 we have

$$\begin{aligned} b_{2^k-1}(n) \equiv \sum _{l=0}^n \left( {\begin{array}{c}2^k\\ l\end{array}}\right) t_{n-l} \pmod {8}. \end{aligned}$$

Moreover, [10, Lemma 4.5] says that

$$\begin{aligned} \left( {\begin{array}{c}2^k\\ l\end{array}}\right) \equiv {\left\{ \begin{array}{ll} 1 \pmod {8} &{}\text {if } l=0,2^k, \\ 4 \pmod {8} &{}\text {if } l=2^{k-2},3\cdot 2^{k-2}, \\ 6 \pmod {8} &{}\text {if } l=2^{k-1}, \\ 0 \pmod {8} &{}\text {otherwise}. \end{array}\right. } \end{aligned}$$

From this description we immediately get the claim for the cases \(0 \le n < 2^{k-2}\) and \(2^{k-2} \le n < 2^{k-1}\). If \(2^{k-1} \le n < 3 \cdot 2^{k-2}\), we get

$$\begin{aligned} b_{2^k-1}(n) \equiv t_n + 4t_{n-2^{k-2}}+6t_{n-2^{k-1}} \equiv t_n + 2t_{n-2^{k-1}} \pmod {8}. \end{aligned}$$

Since n has \(2^{k-1}\) in its binary expansion, we get \(t_{n-2^{k-1}} = - t_n\), and the required congruence follows. Finally, if \(3 \cdot 2^{k-2} \le n < 2^{k}\), we again have \(t_{n-2^{k-1}} = - t_n\) so

$$\begin{aligned} b_{2^k-1}(n) \equiv t_n + 4t_{n-2^{k-2}}+6t_{n-2^{k-1}} + 4t_{n-3 \cdot 2^{k-2}} \equiv -5t_n \pmod {8}. \end{aligned}$$

\(\square \)

As an immediate corollary, we can describe \(n < 2^k\) such that \(b_{2^k-1}(n)\) is (not) a sum of three squares.

Corollary 5.3

Let \(k \ge 3\) and \(n < 2^k\). Then \(b_{2^k-1}(n)\) is not a sum of three squares of integers if and only if one of the following cases holds:

  1. (1)

    \(0 \le n < 2^{k-2}\) and \(t_n = -1\);

  2. (2)

    \(2^{k-1} \le n < 3 \cdot 2^{k-2}\) and \(t_n = 1\).

We move on to the case \(n \ge 2^k\). This time we have \(\nu _2(b_{2^k-1}(n)) \in \{1,2\}\) by Theorem 2.3, which means that it is sufficient to consider \(b_{2^k-1}(n)\) modulo 32. To this end, we need a standard lemma concerning the behavior of binomial coefficients modulo powers of 2 (we provide a proof for completeness).

Lemma 5.4

The following statements hold:

  1. (a)

    For all \(k,n \in \mathbb {N}\) such that \(1 \le n \le 2^k\), we have

    $$\begin{aligned} \nu _2 \left( \left( {\begin{array}{c}2^k\\ n\end{array}}\right) \right) = k -\nu _2(n). \end{aligned}$$
  2. (b)

    For all \(m,n \in \mathbb {N}\) we have

    $$\begin{aligned} \left( {\begin{array}{c}2m\\ 2n\end{array}}\right) \equiv \left( {\begin{array}{c}m\\ n\end{array}}\right) \pmod {2^{\nu _2(m)+1}}. \end{aligned}$$

Proof

By Legendre’s formula we get

$$\begin{aligned} \nu _2 \left( \left( {\begin{array}{c}2^k\\ n\end{array}}\right) \right) = 2^k - 1 - (n - s_2(n) + 2^k-n - s_2(2^k-n) ) = s_2(n) + s_2(2^k-n) -1. \end{aligned}$$

We can express \(s_2(2^k-n)\) as

$$\begin{aligned} s_2(2^k-n) = s_2((2^k-1)-(n-1)) = k - s_2(n-1). \end{aligned}$$

Now, write \(n = 2^{\nu _2(n)} l\), which yields

$$\begin{aligned} s_2(n-1)&= s_2(2^{\nu _2(n)}(l-1) + (2^{\nu _2(n)}-1)) = s_2(l-1) + \nu _2(n) \\&= s_2(l) - 1 + \nu _2(n) = s_2(n)-1 + \nu _2(n). \end{aligned}$$

Combining the above equalities, we get (a).

Moving on to (b), the claim clearly holds for \(n=0\) so we can assume that \(n \ge 1\). We have the congruence

$$\begin{aligned} \left( {\begin{array}{c}2m\\ 2n\end{array}}\right) = \left( {\begin{array}{c}m\\ n\end{array}}\right) \frac{(2m-1)!!}{(2n-1)!!(2m-2n-1)!!} \equiv (-1)^n \left( {\begin{array}{c}m\\ n\end{array}}\right) \pmod {2^{\nu _2(m)+1}}. \end{aligned}$$

If n is even, we immediately obtain (b). If n is odd, we use the inequality

$$\begin{aligned} \nu _2\left( \left( {\begin{array}{c}m\\ n\end{array}}\right) \right) = \nu _2 \left( \frac{m}{n} \left( {\begin{array}{c}m-1\\ n-1\end{array}}\right) \right) \ge \nu _2(m), \end{aligned}$$

which again leads to the desired result. \(\square \)

We are now ready to describe \(b_{2^k-1}(n)\) modulo 32 for \(n \ge 2^k\). This time, the characterization involves two consecutive terms of the PTM sequence.

Theorem 5.5

Fix \(k,i,j \in \mathbb {N}\) such that \(k\ge 3\), \(i < 8\), and \(j<2^{k-3}\). Then for all \(m \ge 1\) we have

$$\begin{aligned} b_{2^k-1}(2^km+2^{k-3}i+j) \equiv t_j(c_i t_m + d_i t_{m-1}) \pmod {32}, \end{aligned}$$

where the coefficients \(c_i, d_i\) do not depend on k and are given in Table 2.

Table 2 The coefficients \(c_i\), \(d_i\)

Proof

Consider first the case \(k \ge 4\). By Lemma 5.1 we have

$$\begin{aligned} b_{2^k-1}(n) = \sum _{l=0}^n b_{2^k}(l) t_{n-l} \equiv \sum _{l=0}^n \left( {\begin{array}{c}2^k\\ l\end{array}}\right) t_{n-l} \pmod {32}. \end{aligned}$$

Now, by Lemma 5.4(a), the binomial coefficients with \(v_2(l) < k-4\) vanish modulo 32. Therefore, assuming that \(n \ge 2^k\), the above sum simplifies to

$$\begin{aligned} b_{2^k-1}(n) \equiv \sum _{l=0}^{16} \left( {\begin{array}{c}2^k\\ 2^{k-4}l\end{array}}\right) t_{n-2^{k-4}l} \equiv \sum _{l=0}^{16} \left( {\begin{array}{c}16\\ l\end{array}}\right) t_{n-2^{k-4}l} \pmod {32}, \end{aligned}$$

where the second congruence follows from Lemma 5.4(b). Furthermore, we can eliminate the terms with l odd, since there is an even number of them and they are all congruent to 16 modulo 32. Therefore, we get the congruence

$$\begin{aligned} b_{2^k-1}(n) \equiv \sum _{l=0}^{8} \left( {\begin{array}{c}16\\ 2l\end{array}}\right) t_{n-2^{k-3}l} \pmod {32}. \end{aligned}$$

To simplify the right-hand side, consider \(b_{2^k-1}\) at indices of the form given in the statement, namely \(n=2^km+2^{k-3}i+j\), where \(m \ge 1\), \(0 \le i < 8\), and \(0 \le j < 2^{k-3}\). By the recurrences defining the PTM sequence, we get

$$\begin{aligned} t_{2^km+2^{k-3}i+j - 2^{k-3}l} = t_j t_{8m+i-l} = t_j \cdot {\left\{ \begin{array}{ll} t_m t_{i-l} &{}\text {if } l \le i, \\ -t_{m-1}t_{l-i} &{}\text {if } l > i. \end{array}\right. } \end{aligned}$$

Therefore, the claimed formula is valid with the coefficients

$$\begin{aligned} c_i = \sum _{l=0}^{i} \left( {\begin{array}{c}16\\ 2l\end{array}}\right) t_{i-l}, \qquad d_i = -\sum _{l=i+1}^{8} \left( {\begin{array}{c}16\\ 2l\end{array}}\right) t_{l-i}, \end{aligned}$$

and a direct calculation (modulo 32) gives their values as in Table 2.

In the case \(k=3\), the expression for \(b_{2^k-1}(n)\) modulo 32 obtained from Lemma 5.1 also contains the sum

$$\begin{aligned} 16 \sum _{l=0}^{n} \left( {\begin{array}{c}6\\ l-2\end{array}}\right) t_{n-l}. \end{aligned}$$

If \(n \ge 8\), then the entire sum vanishes modulo 32, so we again arrive at the formula

$$\begin{aligned} b_{7}(n) \equiv \sum _{l=0}^8 \left( {\begin{array}{c}8\\ l\end{array}}\right) t_{8-l} \pmod {32}. \end{aligned}$$

After a similar calculation as before, we get the result. \(\square \)

Using this result, we can determine the indices \(n \ge 2^k\) such that \(b_{2^k-1}(n)\) is not a sum of three squares. The description turns out to be surprisingly simple.

Corollary 5.6

Let \(k \ge 3\) and \(n \ge 2^k\). The following conditions are equivalent:

  1. (a)

    \(b_{2^k-1}(n)\) is not a sum of three squares;

  2. (b)

    \(t_n = t_{n-2^k} = 1\);

  3. (c)

    \( n = 2^{k} m + l, \) where \(l,m \in \mathbb {N}\) are such that \(l < 2^k\), \(t_m = t_l\), and \(\nu _2(m) \equiv 1 \pmod {2}\).

Proof

Write \(n = 2^km+2^{k-3}i+j\) as in Theorem 5.5. Observe that \(c_i + d_i = - 4t_i\), while \(c_i - d_i\) is not divisible by 4. Hence, the term \(b_{2^k-1}(2^km+2^{k-3}i+j)\) is not a sum of three squares if and only if

$$\begin{aligned} t_m = t_{m-1} = t_i t_j, \end{aligned}$$

which after multiplying both sides by \(t_i t_j\) gives precisely (b).

The equivalence with (c) is obtained by writing \(l = 2^{k-3}i+j\) and observing that \(t_m = (-1)^{\nu _2(m)+1} t_{m-1}\). \(\square \)

6 Counting the Solutions

The aim of this section is to provide estimates for the counting functions of the sets \(S_{2^k-1}\). For real \(x \ge 0\) and \(m \in \mathbb {N}_+\) let

$$\begin{aligned} S_m(x) = S_m \cap [0,x] = \# \{n \le x: b_m(n) \text { is not a sum of three squares} \}. \end{aligned}$$

Using the descriptions of the sets \(S_{2^k-1}\) obtained in the previous sections for various k it is straightforward to check that

$$\begin{aligned} S_{2^k-1}(x) = \delta _k x + O(\log x), \end{aligned}$$

where \(\delta _1 = \delta _2 = 1/12\) and \(\delta _k = 1/6\) for \(k \ge 3\). In the following three results, we provide more precise bounds for \(S_{2^k-1}(x) - \delta _k x\) in the case \(k=1,k=2\) and \(k \ge 3\), respectively. In particular, each lower and upper bound is of the form \(C_1\log _2 x + C_2\), where the constant \(C_1\) is optimal.

Theorem 6.1

For every \(x \ge 6\) we have

$$\begin{aligned} -\frac{5}{3}< S_1(x) - \frac{x}{12} <\frac{1}{2} \log _2 x - \frac{19}{12}. \end{aligned}$$

In particular, the density of the set \(S_1\) in \(\mathbb {N}\) exists and is equal to

$$\begin{aligned} \lim _{x\rightarrow +\infty }\frac{S_1(x)}{x}=\frac{1}{12}. \end{aligned}$$

Moreover, there exists an increasing sequence \((m_k)_{k \in \mathbb {N}} \subset \mathbb {N}\) such that

$$\begin{aligned} S_1(m_l) - \frac{m_l}{12} \sim \frac{1}{2} \log _2 m_l. \end{aligned}$$

Proof

For real \(x \ge 0\) define

$$\begin{aligned} P(x)&= \#\{ s \in \mathbb {N}: 8s + 2t_s + 3 \le x \}, \\ Q(x)&= \sum _{k=0}^{\infty } P \left( \frac{x}{4^k} \right) . \end{aligned}$$

By Corollary 3.3(c) and the relation \(b(2n+1) = b(2n)\), we get

$$\begin{aligned} S_1(x) = Q \left( \frac{x}{4}\right) + Q \left( \frac{x-1}{4}\right) . \end{aligned}$$

Hence, it is sufficient to focus on the function Q. For \(m \in \mathbb {N}\) and \(i=0,1,2,3\) we have the recurrence relations

$$\begin{aligned} Q(4m+i) = Q(m) + P(4m+i). \end{aligned}$$

Also, for \(i < 8\) we have

$$\begin{aligned} P(8m+i) = m +{\left\{ \begin{array}{ll} 0 &{}\text {if } i=0, \\ T_m &{}\text {if } i=1,2,3,4, \\ 1 &{}\text {if } i=5,6,7. \end{array}\right. } \end{aligned}$$

Put

$$\begin{aligned} R(x) = Q(x) - \frac{x}{6}, \end{aligned}$$

so that

$$\begin{aligned} S_1(x) -\frac{x}{12} = R\left( \left\lfloor \frac{x}{4} \right\rfloor \right) + R\left( \left\lfloor \frac{x-1}{4} \right\rfloor \right) + \frac{\left\lfloor \frac{x}{4} \right\rfloor +\left\lfloor \frac{x-1}{4} \right\rfloor }{6} - \frac{x}{12}. \end{aligned}$$

It is readily checked that

$$\begin{aligned} -\frac{1}{3} < \frac{\left\lfloor \frac{x}{4} \right\rfloor +\left\lfloor \frac{x-1}{4} \right\rfloor }{6} - \frac{x}{12} \le -\frac{1}{12}. \end{aligned}$$

Therefore, to obtain the estimates for \(S_1(x) -x/12\), it remains to prove that for each integer \(m \ge 2\) there holds

$$\begin{aligned} -\frac{2}{3} \le R(m) \le \frac{1}{4} \lfloor \log _2 m \rfloor - \frac{1}{4}, \end{aligned}$$

as then for \(x \ge 9\) we get

$$\begin{aligned} -\frac{4}{3} \le R\left( \left\lfloor \frac{x}{4} \right\rfloor \right) + R\left( \left\lfloor \frac{x-1}{4} \right\rfloor \right) < 2 \cdot \frac{1}{4} \left( \log _2 \frac{x}{4} - 1 \right) = \frac{1}{2} \log _2 x -\frac{3}{2} \end{aligned}$$

(for \(x \in [6,9)\) the statement of the theorem follows from direct computation).

This is done by induction on the length L(m) of the binary expansion of m. Direct computation shows that our claim holds when \(2 \le L(m) \le 6\). Hence, let \(L(m) \ge 7\). It is sufficient to prove that there exists an integer \(n \ge 2\) with \(L(n) \le L(m) - 2\) such that

$$\begin{aligned} 0 \le R(m) - R(n) \le \frac{1}{2}. \end{aligned}$$

This is indeed the case, as shown by the following set of identities (ordered according to the residue class modulo 8):

$$\begin{aligned} R(8n)&= R(2n), \\ R(16n+1)&=R(4n+1), \\ R(16n+9)&=R(4n) + \frac{1}{2}, \\ R(16n+2)&=R(4n+2), \\ R(16n+10)&=R(4n) + \frac{1}{3}, \\ R(16n+3)&=R(4n+3), \\ R(16n+11)&=R(4n) + \frac{1}{6}, \\ R(8n+4)&=R(2n+1) + T_n - \frac{1}{2}, \\ R(64n+4)&=R(16n+4), \\ R(64n+20)&=R(16n+2)+1-T_n, \\ R(64n+36)&=R(16n)+1-T_n, \\ R(64n+52)&=R(16n+4), \\ R(16n+12)&=R(4n), \\ R(8n+5)&=R(2n+1)+\frac{1}{3}, \\ R(8n+6)&=R(2n+1)+\frac{1}{6}, \\ R(8n+7)&=R(2n+1). \end{aligned}$$

We move on to the second part of the statement. Define \(m_0 = 0\) and \(m_{l+1} = 16m_l + 36\) for \(l \in \mathbb {N}\). First, we prove inductively that \(R(m_l)= l\). This is clear for \(l = 0\). In general, we have

$$\begin{aligned} R(m_{l+1}) = R(16 m_l + 36) = R( 4m_l) + 1 - T_{m_l} = R(m_l) + 1, \end{aligned}$$

where we have used \(4 \mid m_l\), the recurrence relations above and \(T_{m_l} = 0\) (easily shown by induction). We thus have \(S_1(m_0) = S_1(m_1) =0\) and for \(l \ge 1\) the equality

$$\begin{aligned} S_1(m_{l+1}) - \frac{m_{l+1}}{12}&= R\left( \left\lfloor \frac{m_{l+1}}{4} \right\rfloor \right) + R\left( \left\lfloor \frac{m_{l+1}-1}{4} \right\rfloor \right) - \frac{1}{6} \\&= R(m_{l}) + R(m_{l-1}) + 1 = 2l. \end{aligned}$$

The result follows. \(\square \)

In Fig. 3 we show the graph of the function \(S_1(x) - x/12\) in the range \([1,2^{10}]\) together with the bounds (as in the theorem).

Fig. 3
figure 3

The function \(S_1(x) - x/12\)

From the presented graph, it appears it should be possible to obtain an even better additive constant in the upper bound. To do this, one would need to investigate closer the location of the “spikes” on the graph (some of which correspond to \(x = m_l\)).

The following two results show that the function \(S_1(x)\) is exceptional in the sense that \(S_1(x) - x/12\) is bounded from below by a constant.

Theorem 6.2

For all \(x \ge 1\) we have

$$\begin{aligned} -\frac{1}{6} \log _2 x - \frac{7}{12} < S_{3}(x) - \frac{x}{12} \le \frac{1}{6} \log _2 x - \frac{1}{6}. \end{aligned}$$

In particular, the density of the set \(S_3\) in \(\mathbb {N}\) exists and is equal to

$$\begin{aligned} \lim _{x\rightarrow +\infty }\frac{S_3(x)}{x}=\frac{1}{12}. \end{aligned}$$

Moreover, there exist increasing sequences \((m_l)_{l \in \mathbb {N}}, (n_l)_{l \in \mathbb {N}} \subset \mathbb {N}\) such that

$$\begin{aligned} S_3(m_l) - \frac{m_l}{12}&\sim \frac{1}{6} \log _2 m_l, \\ S_3(n_l) - \frac{n_l}{12}&\sim -\frac{1}{6} \log _2 n_l. \end{aligned}$$

Proof

For \(i=0,1,2,3\) let

$$\begin{aligned} P_i(x) = \#\left\{ n \in \mathbb {N}: 8n+2\left\lfloor \frac{i}{2}\right\rfloor +3+2(-1)^{i}t_{n} \le x\right\} , \end{aligned}$$

so that by Theorem 4.2 we have

$$\begin{aligned} S_3(x) = \sum _{k=1}^{\infty } \sum _{i=0}^3 P_i \left( \frac{x-i}{2 \cdot 4^k} \right) . \end{aligned}$$

This time, put

$$\begin{aligned} P(x)&= \sum _{i=0}^3 P_i(x), \\ Q(x)&= \sum _{k=0}^{\infty } P\left( \frac{x}{4^k}\right) . \end{aligned}$$

Then for any x we have

$$\begin{aligned} Q\left( \frac{x-3}{8} \right) \le S_3(x) \le Q\left( \frac{x}{8} \right) . \end{aligned}$$

Therefore, we need to bound the function \(R(x) = Q(x) -2x/3\). First, for \(n \in \mathbb {N}\) we have the easy to check equalities \(P(n) = \lceil n/2 \rceil \) and

$$\begin{aligned} R(4n+i) = R(n) + {\left\{ \begin{array}{ll} 0 &{}\quad \text {for } i =0,3, \\ \frac{1}{3} &{}\quad \text {for } i =1, \\ -\frac{1}{3} &{}\quad \text {for } i =2. \end{array}\right. } \end{aligned}$$

In a similar fashion as in the previous proof, one can then prove that for \(m \in \mathbb {N}\) there holds

$$\begin{aligned} -\frac{1}{6} \lfloor \log _2 m \rfloor - \frac{1}{6} \le R(m) \le \frac{1}{6} \lfloor \log _2 m \rfloor + \frac{1}{3} \end{aligned}$$

The inequalities for \(S_{3}(x)-x/12\) follow shortly by plugging in \(m=\lfloor x/8 \rfloor \) and \(m=\lfloor (x-3)/8 \rfloor \).

If we define \(m_0=0\) and \(m_{l+1} = 4m_l + 8\), we can inductively compute \(R(m_l/8) = l/3\), and therefore

$$\begin{aligned} S(m_l) - \frac{1}{12} m_l \sim Q\left( \frac{m_l}{8}\right) - \frac{1}{12} m_l = \frac{l}{3} \sim \frac{1}{6} \log _2 m_l. \end{aligned}$$

Similarly, for \(n_0 = 0\) and \(n_{l+1} = 4n_l + 16\), we get \(R(n_l/8) = -l/3\) so

$$\begin{aligned} S(n_l) - \frac{1}{12} n_l \sim -\frac{1}{6}\log _2 n_l, \end{aligned}$$

and the proof is finished. \(\square \)

Fig. 4
figure 4

The function \(S_3(x) - x/12\)

Figure 4 shows the graph of the function \(S_1(x) - x/12\) in the range \([1,2^{10}]\) together with the proved bounds (in red). Again, the bounds are quite accurate, though the additive constants can probably be improved further.

The final result of this section concerns the function \(S_{2^k-1}(x)\). For the sake of clarity, in the proof we make some rough estimates concerning the additive constant (although the constant near \(\log _2 x\) remains optimal).

Theorem 6.3

If \(k \ge 3\), then for all \(x \ge 2^k\) we have

$$\begin{aligned} \left| S_{2^k-1}(x) - \frac{x}{6} \right| \le \frac{2^{k-2}}{3} (\log _2 x - k +26). \end{aligned}$$

In particular, the density of the set \(S_{2^k-1}\) in \(\mathbb {N}\) exists and is equal to

$$\begin{aligned} \lim _{x\rightarrow +\infty }\frac{S_{2^k-1}(x)}{x}=\frac{1}{6}. \end{aligned}$$

Moreover, there exist increasing sequences \((m_l)_{l \in \mathbb {N}}, (n_l)_{l \in \mathbb {N}} \subset \mathbb {N}\) such that

$$\begin{aligned} S_{2^k-1}(m_l) - \frac{m_l}{6}&\sim \frac{2^{k-2}}{3} \log _2 m_l, \\ S_{2^k-1}(n_l) - \frac{n_l}{6}&\sim -\frac{2^{k-2}}{3} \log _2 n_l. \end{aligned}$$

Proof

For \(\varepsilon \in \{1,-1\}\) and non-negative \(x \in \mathbb {R}\) we put

$$\begin{aligned} P_{\varepsilon }(x)&= \#\{1 \le m \le x: t_m = \varepsilon \}, \\ Q_{\varepsilon }(x)&= \sum _{s=0}^{\infty } (-1)^s P_{\varepsilon } \left( \frac{x}{2^s} \right) = \#\left\{ 1 \le m \le x: t_m = \varepsilon \text { and } \nu _2(m) \equiv 0 \pmod {2} \right\} . \end{aligned}$$

Then by Corollary 5.6 we get

$$\begin{aligned} S_{2^k-1}(x)&= S_{2^k-1}(2^k-1) + \sum _{l=0}^{2^k-1} \# \{ 1 \le m \le \frac{x-l}{2^k}: t_m = t_l \text { and } \nu _2(m) \equiv 1 \pmod {2} \} \\&= 2^{k-2} + \sum _{l=0}^{2^k-1} Q_{t_l}\left( \frac{x-l}{2^{k+1}} \right) , \end{aligned}$$

where \(S_{2^k-1}(2^k-1) = 2^{k-2}\) follows from Corollary 5.3. Furthermore, we have the obvious inequality

$$\begin{aligned} 0 \le \sum _{l=0}^{2^k-1} Q_{t_l} \left( \frac{x}{2^{k+1}} \right) - \sum _{l=0}^{2^k-1} Q_{t_l} \left( \frac{x-l}{2^{k+1}} \right) \le 2^k. \end{aligned}$$

Since for each \(\varepsilon = \pm 1\) we have \(t_l = \varepsilon \) for precisely \(2^{k-1}\) indices l, we obtain

$$\begin{aligned} \left| S_{2^k-1}(x) - 2^{k-1} \left( Q_1\left( \frac{x}{2^{k+1}} \right) + Q_{-1}\left( \frac{x}{2^{k+1}} \right) \right) \right| \le 5 \cdot 2^{k-2}. \end{aligned}$$
(4)

Therefore, to bound \( S_{2^k-1}(x) - x/6\) it remains to estimate for \(\varepsilon =\pm 1\) the functions

$$\begin{aligned} R_{\varepsilon }(x) = Q_{\varepsilon }(x) - \frac{x}{3}. \end{aligned}$$

First, note that for \(n \in \mathbb {N}\) we have

$$\begin{aligned} P_{\varepsilon }(n) = \frac{n-\varepsilon }{2} + {\left\{ \begin{array}{ll} \frac{\varepsilon }{2} t_n &{}\quad \text {if } 2\mid n, \\ 0 &{}\quad \text {if } 2\not \mid n. \end{array}\right. } \end{aligned}$$

It follows that

$$\begin{aligned} R_{\varepsilon }(4n+i) = R_{\varepsilon }(n) + {\left\{ \begin{array}{ll} 0 &{}\quad \text {if } i=0,3, \\ \frac{1}{2}(1-\varepsilon t_n) - \frac{1}{3} &{}\quad \text {if } i=1, \\ \frac{1}{2}(1-\varepsilon t_n) - \frac{2}{3} &{}\quad \text {if } i=2. \end{array}\right. } \end{aligned}$$

This leads to the relations

$$\begin{aligned} R_{\varepsilon }(4n)&= R_{\varepsilon }(n), \\ R_{\varepsilon }(8n+1)&= R_{\varepsilon }(2n+1), \\ R_{\varepsilon }(16n+5)&= R_{\varepsilon }(n) + \frac{1}{3}, \\ R_{\varepsilon }(16n+13)&= R_{\varepsilon }(4n+1), \\ R_{\varepsilon }(16n+2)&= R_{\varepsilon }(4n+2), \\ R_{\varepsilon }(8n+6)&= R_{\varepsilon }(2n), \\ R_{\varepsilon }(16n+10)&= R_{\varepsilon }(n)-\frac{1}{3}, \\ R_{\varepsilon }(4n+3)&=R_{\varepsilon }(n). \end{aligned}$$

By induction we obtain for \(\varepsilon = \pm 1\) and all \(n \in \mathbb {N}_+\) the inequality

$$\begin{aligned} |R_{\varepsilon }(n)| \le \frac{1}{12} \lfloor \log _2 n \rfloor + \frac{2}{3}, \end{aligned}$$

which implies

$$\begin{aligned} \left| Q_{\varepsilon }(x) - \frac{x}{3} \right| \le \frac{1}{12}\log _2 x + 1 \end{aligned}$$

for all \(x \ge 1\). The main part of the result follows shortly.

Finally, put \(m_0 = 0\) and \(m_{l+1} = 16m_l + 5 \cdot 2^{k+1}\). Also, let \(\alpha = (k+1) \bmod {2}\). Using the fact that \(2^{k+1} \mid m_l\), from the recurrence relations for \(R_{\varepsilon }\) we get

$$\begin{aligned} R_{\varepsilon }(2^{\alpha }m_{l+1})&= R_{\varepsilon }(2^{4+\alpha } m_l + 5 \cdot 2^{k+1 + \alpha }) = R_{\varepsilon }(2^{3-k} m_l + 5) \\&= R_{\varepsilon }(2^{-1-k} m_l) + \frac{1}{3} = R_{\varepsilon }(2^{\alpha }m_l) + \frac{1}{3}. \end{aligned}$$

It follows that

$$\begin{aligned} Q_{\varepsilon }\left( \frac{m_l}{2^{k+1}} \right) - \frac{m_l}{3 \cdot 2^{k+1}} = R_{\varepsilon }(2^{\alpha }m_l) = \frac{l}{3} \sim \frac{1}{12} \log _2 m_l, \end{aligned}$$

and it remains to use (4).

Similarly, we can take \(n_0 = 0\) and \(n_{l+1} = 16n_l + 10 \cdot 2^{k+1}\). \(\square \)

7 Computational Results, Questions, Problems and Conjectures

In this section, we discuss possible directions for further research and present some conjectures and computational results.

To begin, recall that in Sect. 3 we have defined \((f_n)_{n \in \mathbb {N}}\) to be the increasing sequence such that \(S_1' = \{f_n: n \in \mathbb {N}\}\), and asked whether it is regular. We have performed some experimental computations in Mathematica 13 with the help of the IntegerSequences package by Eric Rowland [23], available at https://ericrowland.github.io/packages.html. More precisely, for each \(m \le 30\) we have used the FindRegularSequenceRecurrence function, which did not find a finite set of (plausible) \(\mathbb {Z}\)-linear relations between the elements of the m-kernel \(K_m((f_n)_{n \in \mathbb {N}})\). Hence, we expect that following conjecture holds.

Conjecture 7.1

The sequence \((f_{n})_{n\in \mathbb {N}_{+}}\) is not m-regular for any \(m \ge 2\).

On the other hand, note that we if we consider the decomposition

$$\begin{aligned} S_1'=\bigcup _{k=0}^{\infty }U_{k} \end{aligned}$$

into pairwise disjoint sets \(U_{k}=\{2^{2k+1}(8s+2t_{s}+3):\;s\in \mathbb {N}\}\), then for each \(k\in \mathbb {N}\) the sequence \((2^{2k+1}(8s+2t_{s}+3))_{s\in \mathbb {N}}\) is 2-regular.

Next, it is natural to ask whether it is possible to obtain results on the representation of \(b_m(n)\) as a sum of three squares for any \(m \in \mathbb {N}_+\).

Problem 7.2

Characterize the set \(S_m\) for \(m \in \mathbb {N}_+\).

If the valuations \(\nu _2(b_m(n))\) are bounded, then the direct approach used in this paper, namely reduction modulo a fixed power of 2, is sufficient to give a complete description of \(S_m\). The following proposition implies that in this case \(S_m\) is a 2-automatic set (its characteristic sequence is 2-automatic).

Proposition 7.3

For each \(m \in \mathbb {N}_+\) and \(p \in \mathbb {N}\) the sequence \((b_m(n) \bmod {2^p})_{n \ge 0}\) is 2-automatic.

Proof

Take any \(k \ge p-1\) such that \(2^k \ge m\). Note that \((b_m(n))_{n \ge 0}\) is the convolution of the sequence \((b_{2^k}(n))_{n \ge 0}\) with \(2^k-m\) copies of the PTM sequence \((t_n)_{n \ge 0}\). They are both 2-regular when treated as sequences over the ring \(\mathbb {Z}/2^p\mathbb {Z}\) (for \((b_{2^k}(n))_{n \ge 0}\) this follows from Lemma 5.1). Hence, \((b_m(n) \bmod {2^p})_{n \ge 0}\) is 2-regular as the convolution of 2-regular sequences. The result follows from the fact that a 2-regular sequence attaining finitely many values is necessarily 2-automatic. \(\square \)

Unfortunately, we do not know even for a single value \(m \ne 2^k-1\), whether or not the valuations \(\nu _2(b_m(n))\) are bounded. It is conjectured that they are unbounded for all \(m \ne 2^k-1\) (see [10, Conjecture 5.3]). Nevertheless, this does not rule out 2-automaticity of the set \(S_m\). Surprisingly, numerical results for \(m \le 30\) (obtained with help of the IntegerSequences package) suggest that the sets \(S_m\) are 2-automatic for odd m, except for \(m=17,21\).

It should be possible to get some partial results if we restrict our attention to arithmetic progressions along which \(\nu _2(b_m(n))\) is bounded. For example, [10, Theorem 5.4] provides a collection of suitable arithmetic progressions \((2^rn +s)_{n \in \mathbb {N}}\) such that \(\nu _2(b_2(2^rn +s))\) is constant. By Proposition 7.3, the set of n such that \(b_2(2^rn +s)\) is a sum of three squares, is 2-automatic.

A related interesting problem concerns the behavior of \(b_m(n)\) modulo a fixed power of 2.

Problem 7.4

For \(m \in \mathbb {N}_+\) and \(p \in \mathbb {N}\) characterize \(b_m(n) \bmod {2^p}\).

We already know that this sequence is 2-automatic and may ask whether it can be characterized in terms of simpler 2-automatic sequences. The congruences obtained in the previous sections for subsequences of the form \(b_{2^k-1}(2^r n + s)\) are all “admissible” in the sense of [14], that is, only involve \(t_n\) and \((-1)^{\nu _2(n)}\). In the case \(k \ge 3\) Theorem 5.5 provides a congruence in terms of \(t_n, t_{n-1}\) that can be transformed into an admissible one due to the relation \(t_{n-1} = (-1)^{\nu _2(n)+1} t_n\).

It turns out that other interesting 2-automatic sequences already appear if we consider \(b_m(n)\) modulo suitable powers of 2. By inspecting modulo 32 the subsequences described in Proposition 3.7, we have found (without proof) the following set of congruence relations:

$$\begin{aligned} b(8n+2)&\equiv 2t_n+16\sigma _n \pmod {32}, \\ b(8n+6)&\equiv 6t_n + 16\sigma _n+16n \pmod {32}, \\ b(16n+8)&\equiv (10 + 8n^2)t_n +16\sigma _n \pmod {32}, \end{aligned}$$

where \(\sigma _n\) counts modulo 2 the number of blocks of contiguous 1’s in the binary expansion of n. We have later learned that Alkauskas [2, Theorem 2] obtained a set of relations that describe the same sequences and involve the Rudin–Shapiro sequence instead of \((\sigma _n)_{n \in \mathbb {N}}\). It can be checked that both descriptions are equivalent.

Another sequence that arises in this way is the regular paperfolding sequence \((p_n)_{n \in \mathbb {N}_+}\) defined by \(p_{2n} = p_n\) and \(p_{2n+1} = (-1)^n\) (see for example [3, Example 5.1.6]). If we let \(P(x)= \sum _{n \ge 1} p_n x^n\), then through manipulation of power series, for m even one can obtain the congruence relation

$$\begin{aligned} B_m(x) \equiv (1-x)^m (1+2mP(x)) \pmod {2^{\nu _2(m)+3}}. \end{aligned}$$

This is essentially a generalization of Lemma 5.1.

We now consider some natural modifications of the original equation \(b_m(n) = x^2+y^2+y^2\). We have obtained precise characterization of those \(n\in \mathbb {N}\) such that b(2n) is a sum of three squares. In particular, the set of such numbers has natural density equal to 11/12. For a given n not of the form \(2^{2k+1}(8s+2t_{s}+3)\), by analyzing the solution set (xyz) of the equation \(b(2n)=x^2+y^2+z^2\), we found that in many cases one of the values xyz is a square itself, i.e., the Diophantine equation

$$\begin{aligned} b(2n)=x^2+y^2+z^4 \end{aligned}$$

has a solution in non-negative integers. More precisely, for \(n\le 10^3\) we know that there are exactly 916 values of n such that b(2n) is a sum of three squares. Among them, there are exactly 831 values of n such that b(2n) is a sum of two squares and a fourth power. This large number of solutions suggest the following conjecture.

Conjecture 7.5

Let \(Q_{1}:=\{n\in \mathbb {N}:\;b(2n)=x^2+y^2+z^4\;\text{ for } \text{ some }\;x, y, z\in \mathbb {N}\}\). The set \(Q_{1}\) is infinite. Moreover, the set \(Q_{1}\) has positive natural density in \(\mathbb {N}\).

On the other hand, there are exactly seven values of \(n\le 1000\) such that b(2n) is a sum of a square and two fourth powers. This may suggest that the number of solutions of the equation \(b(2n)=x^2+y^4+z^4\) is finite. However, due to limited range of our computations we instead formulate the following:

Question 7.6

Is the set of n such that \(b(2n)=x^2+y^4+z^4\) has a solution in integers xyz infinite?

An even more interesting and difficult question is whether the set

$$\begin{aligned} {\mathcal {T}}=\{n\in \mathbb {N}:\;b(2n)=x^2+y^2\} \end{aligned}$$

is infinite or not. Because we know the behaviour of \(b(n)\bmod {16}\) we can easily prove that the complement of \({\mathcal {T}}\), i.e., \(\mathbb {N}\setminus {\mathcal {T}}\) is infinite. Indeed, from Proposition 3.2 we have \(b(16n+4)\equiv 4t_{n}\pmod {16}\). If \(t_{n}=-1\), then \(b(16n+4)\equiv 12\pmod {16}\) and thus \(b(16n+4)\) is not a sum of two squares.

To get a clue what can be expected in the case of the set \({\mathcal {T}}\), we computed the values of b(2n) for \(n\le 2^{20}\) and checked whether b(2n) is a sum of two squares. We put

$$\begin{aligned} {\mathcal {T}}(x)=\#\{n\le x:\;n\in {\mathcal {T}}\} \end{aligned}$$

and in Table 3 we present the values of \({\mathcal {T}}(2^{n})\) for \(n\le 20\).

Table 3 The number \({\mathcal {T}}(2^{n})\) for \(n\le 20\)

We also define

$$\begin{aligned} {\mathcal {S}}=\{r_{2}(b(2n)):\;n\in \mathbb {N}\}, \end{aligned}$$

where \(r_{2}(m)\) is the number of representations of m as a sum of two squares. Let us recall that

$$\begin{aligned} r_{2}(m)=\sum _{d|m,d\equiv 1\pmod {2}}(-1)^{\frac{d-1}{2}}. \end{aligned}$$

In the considered range, i.e., \(n\le 2^{20}\) the set \({\mathcal {S}}\) contains 0 and 35 positive values \(s_{1}\le \cdots \le s_{35}\). In Table 4 below, we present the following values: \(s_{i}\), \(l_{i}\)—the number of times \(s_{i}\) is attained, and \(n_{i}\)—the smallest value of n such that \(r_{2}(b(2n))=s_{i}\).

Table 4 Values of \(s_{i}, l_{i}\) and \(n_{i}\) for \(i\le 35\)
Table 5 Values of \({\mathcal {T}}(2^{m})\frac{m}{2^{m}}\) for \(m=10, \ldots , 20\)

Our numerical computations suggest the following.

Conjecture 7.7

The set \({\mathcal {T}}\) is infinite.

The following heuristic reasoning provides further evidence towards our conjecture. More precisely, recall that the counting function of the sums of two squares up to x is \(O(x/\sqrt{\log x})\). Thus, one can say that the probability that a random positive integer n can be written as a sum of two squares of integers is \(c/\sqrt{\log n}\). Since, \(\log _{2} b(n)\approx \frac{1}{2}(\log _{2}n)^{2}\) one could conjecture that the expectation that b(n) is a sum of two squares is \(c'/\log n\) for some positive constant \(c'\), provided that b(n) behaves like a random integer of its size. As a consequence, up to x, we would have at least

$$\begin{aligned} \sum _{n\le x} \frac{1}{\log n}=\frac{x}{\log x} +O(x/\log ^{2} x) \end{aligned}$$

values of n such that b(n) is a sum of two squares. We dare to formulate the following statement.

Conjecture 7.8

There exists a positive real number c such that

$$\begin{aligned} {\mathcal {T}}(x)=c\frac{x}{\log x}+O(x/\log ^{2} x) \end{aligned}$$

as \(x\rightarrow +\infty \).

Although limited, our computations confirm such an expectation. In Table 5 we give the values \({\mathcal {T}}(2^{m})\frac{m}{2^{m}}\) for \(m=10, \ldots , 20\).

Remark 7.9

The expectation that b(n) behaves like a random integer of its size is very likely. Indeed, numerical computations suggest that for any odd integer m the sequence \((b(n)\pmod {m})_{n\in \mathbb {N}}\) is uniformly distributed; i.e., for any \(r\in \{0, 1, \ldots , m-1\}\) we have

$$\begin{aligned} \lim _{N\rightarrow +\infty }\frac{\#\{n\le N:\;b(n)\equiv r\pmod {m}\}}{N}=\frac{1}{m}. \end{aligned}$$

However, according to the best knowledge of the authors, it is not even known whether the set of prime numbers p such that p|b(n) for some n, is infinite.