1 Introduction

Given any finite set A of natural numbers, let M(A) denote the largest cardinality of a subset of A on which the Euler totient function \(\varphi (n)\) is nondecreasing (or weakly increasing), thus \(\varphi (n) \le \varphi (m)\) whenever \(n \le m\) are both in the subset. We also write M(x) for M([x]), where [x] denotes the set \([x] {:}{=}\{n \in \mathbb {N}: n \le x \}\). For instance, \(M(6)=5\), since \(\varphi \) is nondecreasing on \(\{1,2,3,4,5\}\) or \(\{1,2,3,4,6\}\) but not \(\{1,2,3,4,5,6\}\). The first few values of M(x) are

$$\begin{aligned} 1, 2, 3, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 11, 12, 12, \ldots \end{aligned}$$

(https://oeis.org/A365339). Since \(\varphi (p)=p-1\) for primes p, we clearly haveFootnote 1

$$\begin{aligned} M(x) \ge \pi (x) = \left( 1+O\left( \frac{1}{\log x}\right) \right) \frac{x}{\log x} \end{aligned}$$
(1.1)

for \(x \ge 2\), by the prime number theorem. As is customary, we use \(\pi (x)\) to denote the number of primes in [x]. In the opposite direction, it was shown in [22] that

$$\begin{aligned} M(x) \le (1-c+o(1)) W(x) \end{aligned}$$

as \(x \rightarrow \infty \) for some absolute constant \(c > 0\), where

$$\begin{aligned} W(x) {:}{=}\# \{ \varphi (n): n \in [x] \} \end{aligned}$$

(https://oeis.org/A061070) is the range of values of the Euler totient function up to x, and \(\# A\) denotes the cardinality of a set A. The precise order of growth of W is known [11]; applying this estimate (or the earlier bounds from [18]), we obtain the upper bound

$$\begin{aligned} M(x) \le \exp ( (C+o(1)) \log _3^2 x ) \frac{x}{\log x} \end{aligned}$$

as \(x \rightarrow \infty \) for an explicit constant \(C = 0.81781\ldots \), where we use the abbreviations

$$\begin{aligned} \log _2 x {:}{=}\log \log x; \quad \log _3 x {:}{=}\log \log \log x. \end{aligned}$$

The main result of this paper is to improve the upper bound on M(x) to asymptotically match the lower bound, with only a slight degradation in the error term.

Theorem 1.1

(New upper bound) We have \(M(x) \le \left( 1+O\left( \frac{\log ^5_2 x}{\log x}\right) \right) \frac{x}{\log x}\) for all \(x \ge 10\). In particular, by (1.1), we have

$$\begin{aligned} \pi (x) \le M(x) \le \left( 1+O\left( \frac{\log ^5_2 x}{\log x}\right) \right) \pi (x) \end{aligned}$$
(1.2)

or equivalently

$$\begin{aligned} M(x) = \left( 1+O\left( \frac{\log ^5_2 x}{\log x}\right) \right) \frac{x}{\log x}. \end{aligned}$$

This answers a question of Erdős [10, Sect. 9] https://www.erdosproblems.com/49, who asked if \(M(x) = (1+o(1)) \pi (x)\). As corollary, we may also answer a “not unattackable” question from [22, p. 381]:

Corollary 1.2

If \({{\mathcal {I}}}\) is a subset of [x] on which \(\varphi \) is nondecreasing, then \(\sum _{n \in {{\mathcal {I}}}} \frac{1}{n} \le \log _2 x + O(1)\) for \(x \ge 10\).

Proof

We may assume x is an integer. By summation by parts (or telescoping series), we have

$$\begin{aligned} \sum _{n \in {{\mathcal {I}}}} \frac{1}{n}&= \sum _{m \le x} \frac{1}{m(m+1)} \sum _{n \in {{\mathcal {I}}}: n \le m} 1 + \frac{1}{x+1} \sum _{n \in {{\mathcal {I}}}} 1 \\&\le 1 + \sum _{m \le x} \frac{1}{m^2} \sum _{n \in {{\mathcal {I}}}: n \le m} 1. \end{aligned}$$

By Theorem 1.1, we have

$$\begin{aligned} \sum _{n \in {{\mathcal {I}}}: n \le m} 1 \le \left( 1+O\left( \frac{\log ^5_2 m}{\log m}\right) \right) \frac{m}{\log m} \end{aligned}$$

for all \(m \ge 10\). The claim then follows from the absolute convergence of \(\sum _{m \ge 10} \frac{\log ^5_2 m}{m \log ^2 m}\), and the standard asymptotic \(\sum _{10\le m \le x} \frac{1}{m \log m} = \log _2 x + O(1)\) for \(x \ge 10\). \(\square \)

In [22] the much stronger claim

$$\begin{aligned} M(x) \le \pi (x) + O(1) \end{aligned}$$
(1.3)

was posed as an open question, with numerics in fact suggesting the even more precise conjecture

$$\begin{aligned} M(x)=\pi (x) + 64 \end{aligned}$$
(1.4)

for \(x \ge 31957\) (see [22, Sect. 9], where the conjecture was verifiedFootnote 2 for \(x = 10^m\) for \(m \le 7\)). Unfortunately, there appear to be several obstacles to establishing such a strong result, which we discuss in Sect. 4. Nevertheless, some improvements in the error term in (1.2) may be possible, particularly if one is willing to establish results conditional on such conjectures as Cramér’s conjecture [4] or quantitative forms of the Dickson–Hardy–Littlewood prime tuples conjecture [6, 15]; again, see Sect. 4.

Remark 1.3

The lengths \(M^\downarrow (x)\) (resp. \(M^0(x)\)) of the longest sequences in [x] on which \(\varphi \) is nonincreasing (resp. constant), rather than nondecreasing, are considerably smaller than M(x). Indeed, in [22] the bounds

$$\begin{aligned} M^0(x) + x^{0.18} < M^\downarrow (x) \ll x \exp \left( -\left( \frac{1}{2}+o(1)\right) \log ^{1/2} x \log ^{1/2}_2 x \right) \end{aligned}$$

were shown for large x, with the speculation that “perhaps” \(M^\downarrow (x) \asymp M^0(x)\), while it is also known (see [24, 25, Sect. 4] for the upper bound, and [17] for the lower bound, which builds upon earlier work in [1, 16]) that

$$\begin{aligned} x^{0.7156} \ll M^0(x) \ll x \exp (-(1+o(1)) \log x \log _3 x / \log _2 x) \end{aligned}$$

for large x, with the upper bound conjectured to be sharp. See [22] for further discussion.

The arguments in [22] were largely based on an analysis of equations of the form \(\varphi (n)=\varphi (n+k)\). To get the more precise asymptotics of Theorem 1.1, we proceed differently, as we shall now explain. Perhaps surprisingly, we do not use deep results from analytic number theory; aside from the prime number theorem with classical error term (Lemma 1.6), all of our tools are elementary.

It is first necessary to establish the following sharp inequality regarding the (weighted) multiplicity of the function \(d \mapsto \varphi (d)/d\).

Proposition 1.4

(Preliminary inequality) For any positive rational number q, one has

$$\begin{aligned} \sum _{d: \frac{\varphi (d)}{d} = q} \frac{1}{d} \le 1. \end{aligned}$$

The reason we need to establish this inequality is as follows. Suppose for contradiction that the inequality failed, then one could find a rational number q and a finite set \({{\mathcal {D}}}\) of natural numbers d with \(\frac{\varphi (d)}{d}=q\) such that

$$\begin{aligned} \sum _{d \in {{\mathcal {D}}}} \frac{1}{d} > 1. \end{aligned}$$

Observe that if \(n = dp\) for \(d \in {{\mathcal {D}}}\) and p a prime larger than the largest element \(\max {{\mathcal {D}}}\) of \({\mathcal D}\), then

$$\begin{aligned} \varphi (n) = \varphi (d) \varphi (p) = qd (p-1) = q (n-d). \end{aligned}$$
(1.5)

To exploit this, let A be the set of numbers in [x] of the form dp, where \(d \in {{\mathcal {D}}}\) and \(p > \max \mathcal {D}\) is a prime, and let \(A'\) be the set A with any consecutive elements of A with difference less than \(\max {{\mathcal {D}}}\) deleted. If \(d_1p_1 < d_2 p_2\) are consecutive elements of \(A'\), then by (1.5) we have

$$\begin{aligned} \varphi (p_1 d_1) - \varphi (p_2 d_2) = q ( p_1 d_1 - d_1 - p_2 d_2 + d_2) \ge q (\max \mathcal {D} - d_1 + d_2) \ge q d_2 > 0. \end{aligned}$$

In particular, \(\varphi \) is increasing on \(A'\), and one can check using the prime number theorem (as well as standard upper bound sieves to bound the number of elements deleted) that

$$\begin{aligned} \# A' = \left( \sum _{d \in {{\mathcal {D}}}} \frac{1}{d} + o(1)\right) \frac{x}{\log x} \end{aligned}$$

as \(x \rightarrow \infty \), which would contradict Theorem 1.1. Thus we must prove Proposition 1.4 first. Fortunately, this is easy to accomplish thanks to a minor miracle: the sum appearing in Proposition 1.4 can be computed almost exactly whenever it is non-zero! See Lemma 2.1 below.

We now informally outline the proof of Theorem 1.1. Standard results from the anatomy of integers will tell us that all numbers n in [x] outside of a small exceptional set E will be of one of the following two forms:

(\(A_1\)):

\(n=dp\), where d is a very smooth number (all prime factors small), and p is a large prime.

(\(A_2\)):

\(n=dps\), where p is a medium-sized prime, d has all prime factors less than p, and s is an almost prime (a prime or product of two primes), with all prime factors of s much larger than p.

The precise definitions of \(A_1\), \(A_2\) and E are given in Sect. 3, with the decomposition justified by Lemma 3.1 and Proposition 3.2.

Suppose first that \(n=dps\) is of type \(A_2\). From multiplicativity we have the identity

$$\begin{aligned} \varphi (n) = \frac{\varphi (d)}{d} \left( 1 - \frac{1}{p}\right) \frac{\varphi (s)}{s} n; \end{aligned}$$

since s is almost prime and has large prime factors we are led to the approximation

$$\begin{aligned} \varphi (n) \approx \frac{\varphi (d)}{d} \left( 1 - \frac{1}{p}\right) n. \end{aligned}$$

The upshot of this approximation is that if we restrict d to a fixed value, and restrict n to a somewhat short interval, then \(\varphi (n)\) can only be nondecreasing if the prime p is also essentially nondecreasing. The presence of the unspecified factor s allows one to decouple the magnitude of n from the magnitude of p, even when d is fixed; as a consequence, this additional monotonicity constraint on p turns out to significantly cut down the possible length of a sequence of numbers of this form in which \(\varphi \) is increasing, to the point where the contribution of this case is significantly less than \(\frac{x}{\log x}\).

If instead \(n=dp\) is of type \(A_1\), then we similarly have the approximation

$$\begin{aligned} \varphi (n) \approx \frac{\varphi (d)}{d} n, \end{aligned}$$

and so the quantity \(\frac{\varphi (d)}{d}\) must (heuristically, at least) be locally nondecreasing in order for \(\varphi (n)\) to be nondecreasing. Upon applying the prime number theorem, one can basically conclude that the size of such a sequence is at most

$$\begin{aligned} \left( \sup _q \sum _{d: \frac{\varphi (d)}{d}=q} \frac{1}{d} + o(1)\right) \frac{x}{\log x}, \end{aligned}$$

and one can use Lemma 1.4 to conclude (after performing a more careful accounting of error terms).

The argument used to establish Theorem 1.1 can also be adapted to treat the analogous problem for the sum of divisors function \(\sigma (n)\) as well as the Dedekind totient function \(\psi (n)\): see Sect. 4.4.

The author is supported by NSF grant DMS-1764034. We thank Wouter van Doorn, Kevin Ford, Paul Pollack and Carl Pomerance for helpful comments, suggestions, and references, and to Shengtong Zhang to providing the key ingredient needed to obtain the analogous results for the sum of divisors function. We also thank the anonymous referees for several useful comments and references, including [17] and Remark 4.7. We also thank Thomas Bloom for the web site https://www.erdosproblems.com/49, where the author discovered this problem.

1.1 Notation and Basic Tools

We use the usual asymptotic notation \(X \ll Y\), \(Y \gg X\), or \(X = O(Y)\) to denote the claim \(|X| \le CY\) for an absolute constant C, \(X \asymp Y\) to denote the claim \(X \ll Y \ll X\), and \(X=o(Y)\) to denote the claim \(|X| \le c(x) Y\) for some quantity c(x) that goes to zero as \(x \rightarrow \infty \).

The symbol p will be understood to range over primes unless otherwise indicated.

For any \(y \ge 2\), we let \(\mathbb {N}_{\le y}\) denote the set of y-smooth numbers, that is the natural numbers whose prime factors are all less than or equal to y. We similarly let \(\mathbb {N}_{<y}\) denotes the natural numbers whose prime factors are all strictly less than y.

We record a useful (if somewhat crude) estimate:

Lemma 1.5

(Rankin trick) If \(y \ge 10\), and \(a_d\) is a non-negative real number for every \(d \in \mathbb {N}_{\le y}\), then

$$\begin{aligned} \sum _{d \in \mathbb {N}_{\le y}} a_d \ll \log y \sup _{d \in \mathbb {N}_{\le y}}\left( d^{1-\frac{1}{\log y}} a_d \right) . \end{aligned}$$

One could obtain sharper bounds here by using standard bounds on smooth numbers here, such as those in [5], but the above crude estimate suffices for our application. In this lemma we allow the quantities on either side to be infinite, though in applications we will only use the lemma when the right-hand side is finite, as the claim is trivial otherwise.

Proof

By Euler product factorization and Mertens’ theorems, we have

$$\begin{aligned} \sum _{d \in \mathbb {N}_{\le y}} \frac{1}{d^{1-\frac{1}{\log y}}}&= \prod _{p \le y} \left( 1 + \frac{p^{1/\log y}}{p} + O\left( \frac{1}{p^{3/2}} \right) \right) \\&= \exp \left( \sum _{p \le y} \frac{1}{p} + O\left( \frac{\log p/\log y}{p} \right) + O\left( \frac{1}{p^{3/2}} \right) \right) \\&= \exp ( \log _2 y + O(1) ) \\&\ll \log y. \end{aligned}$$

The claim now follows by bounding \(a_d \le \frac{1}{d^{1-\frac{1}{\log y}}} \sup _{d' \in \mathbb {N}_{\le y}}\left( (d')^{1-\frac{1}{\log y}} a_{d'}\right) \). \(\square \)

We also need some well known bounds for primes in intervals:

Lemma 1.6

(Primes in intervals) Let \(y \ge 10\), and let I be an interval in [2, y]. Let |I| denote the length of I. Then the number of primes in I is equal to

$$\begin{aligned} \int _I \frac{\textrm{d}t}{\log t} + O( y \exp (-c\sqrt{\log y})) \end{aligned}$$

for some absolute constant \(c>0\). In particular, we have the crude upper bound of \(O(y/\log y)\).

Proof

Immediate from the prime number theorem with classical error term. \(\square \)

As a corollary of the prime number theorem, we obtain a Mertens-type estimate.

Lemma 1.7

(Mertens-type bound) If \(2 \le z \le y\), then

$$\begin{aligned} \sum _{z \le p \le y} \frac{1}{p} \ll \frac{\exp (-c \sqrt{\log z}) + \log \frac{y}{z}}{\log z} \end{aligned}$$

for an absolute constant \(c>0\).

Proof

By Mertens’ second theorem we have

$$\begin{aligned} \sum _{z \le p \le y} \frac{1}{p}&= \log \log y - \log \log z + O\left( \frac{1}{\log z}\right) \\&\ll \log \left( 1 + \frac{\log (y/z)}{\log z}\right) + \frac{1}{\log z} \end{aligned}$$

which is acceptable if \(y > 2z\) (in which case we may discard the \(\exp (-c \sqrt{\log z}) \) term). In the remaining case \(z \le y \le 2z\), one can bound \(\frac{1}{p} \ll \frac{1}{y}\) and apply Lemma 1.6. \(\square \)

2 Proof of Preliminary Inequality

We now prove Proposition 1.4. It turns out that (somewhat remarkably) one has a reasonably exact formula for the sum of interest, which implies Proposition 1.4 as an immediate corollary:

Lemma 2.1

(Exact formula) Let \(q=a/b\) be a positive rational number in lowest terms. Then the expression \(\sum _{d: \frac{\varphi (d)}{d} = q} \frac{1}{d}\) either vanishes, or is equal to \(\prod _{p \in {{\mathcal {P}}}} \frac{1}{p-1}\), for some finite set of primes \({{\mathcal {P}}}\) whose largest element is equal to the largest prime factor of b (with \({{\mathcal {P}}}\) empty when \(b=1\)). In particular, Proposition 1.4 holds.

Proof

When \(b=1\), the only possible value of q that is of the form \(\frac{\varphi (d)}{d}\) is \(q=1\), which is attained precisely when \(d=1\), so the identity holds in this case.

To handle the \(b>1\) case we induct on the largest prime factor \(p_1\) of b, assuming that the claim has already been proven for smaller values of \(p_1\) (with the convention that \(p_1=1\) when \(b=1\)). We may assume that q is of the form \(\frac{\varphi (d)}{d}\) for at least one d. For such a d, we have

$$\begin{aligned} \frac{a}{b} = q = \frac{\varphi (d)}{d} = \prod _{p|d} \frac{p-1}{p}. \end{aligned}$$

From this identity we see that the largest prime factor \(p_1\) of b must also be the largest prime factor of d. Thus we can write \(d = p_1^i d'\) where \(i \ge 1\), \(d' \in \mathbb {N}_{<p_1}\) and \(\frac{\varphi (d')}{d'} = q'\), where \(q' = \frac{a'}{b'}\) is equal to \(\frac{p_1}{p_1-1} q\) in lowest terms. By the same computation, the largest prime factor \(p'_1\) of \(b'\) is equal to that of \(d'\), and thus \(p'_1 < p_1\). Conversely, if \(d'\) is such that \(\frac{\varphi (d')}{d'} = \frac{a'}{b'}\), then the largest prime factor of \(d'\) must equal \(p'_1\), so that \(d'\) is coprime to \(p_1\), and hence any d of the form \(d = p_1^i d'\) with \(i \ge 1\) is such that

$$\begin{aligned} \frac{\varphi (d)}{d} = \frac{p_1-1}{p_1} \frac{\varphi (d')}{d'} = q. \end{aligned}$$

Thus we have

$$\begin{aligned} \sum _{d: \frac{\varphi (d)}{d} = q} \frac{1}{d} = \sum _{i=1}^\infty \sum _{d': \frac{\varphi (d')}{d'} = q'} \frac{1}{p_1^i d'} = \frac{1}{p_1-1} \sum _{d': \frac{\varphi (d')}{d'} = q'} \frac{1}{d'}. \end{aligned}$$

The claim now follows from the induction hypothesis. \(\square \)

Remark 2.2

From Lemma 2.1 we see that equality in Proposition 1.4 only holds when \(q=1\) or \(q=\frac{1}{2}\), with the improved inequality \(\sum _{d: \frac{\varphi (d)}{d} = q} \frac{1}{d} \le \frac{1}{2}\) holding in all other cases. The equality when \(q = \frac{1}{2}\) produces an almost viable counterexample to conjectures such as (1.3); see Sect. 4.2 below.

Remark 2.3

Lemma 2.1 is closely related to the well known fact (see e.g., [13]) that if nm are natural numbers, then \(\varphi (n)/n\) and \(\varphi (m)/m\) are equal if and only if nm have exactly the same set of prime factors.

3 Main Argument

We now prove Theorem 1.1. We may of course take x to be larger than any given absolute constant. We will need some intermediate scales

$$\begin{aligned} 1< L< D^{1/\log L}< D< \exp (\sqrt{\log x})< R < x. \end{aligned}$$
(3.1)

There is some flexibility in how to select these scales; we will make the choice

$$\begin{aligned} L&{:}{=}\log ^{10} x = \exp (10 \log _2 x) \end{aligned}$$
(3.2)
$$\begin{aligned} D&{:}{=}\exp (\log _2^3 x) = \left( \exp (\log _2^2 x/10)\right) ^{\log L} \end{aligned}$$
(3.3)
$$\begin{aligned} R&{:}{=}x^{\frac{1}{3\log _2 x}} = \exp \left( \frac{\log x}{3\log _2 x} \right) . \end{aligned}$$
(3.4)

Note that these scales are widely separated, in the sense that any fixed power of one of the expressions in (3.1) is still less than the next expression in (3.1), if x is large enough. For instance, the savings \(\exp (-c\sqrt{\log x})\) arising from Lemma 1.6 can easily absorb any polynomial losses in L and D. In a similar spirit, we have \(\log \frac{R}{L^2} \asymp \log \frac{R}{L} \asymp \log R\), \(\log \frac{x}{DL} \asymp \log \frac{x}{D} \asymp \log x\), \(\log (DL) \asymp \log D\), and so forth.

We observe the triangle inequalityFootnote 3

$$\begin{aligned} M(A \cup B) \le M(A) + M(B) \end{aligned}$$
(3.5)

as well as the trivial bound

$$\begin{aligned} M(A) \le \# A. \end{aligned}$$
(3.6)

We shall cover the set [x] by three (slightly overlapping) sets

$$\begin{aligned}{}[x] = A_1 \cup A_2 \cup E \end{aligned}$$
(3.7)

which by (3.5), (3.6) implies that

$$\begin{aligned} M(x) \le M(A_1) + M(A_2) + \# E. \end{aligned}$$
(3.8)

We will control each of the three terms on the right-hand side separately.

The exceptional set E is defined to be the set of all \(n \in [x]\) having an unusual prime factorization in at least one of the following senses:

  1. (i)

    (Smallness) \(n \le \frac{x}{L}\).

  2. (ii)

    (Smoothness) \(n \in \mathbb {N}_{\le R}\).

  3. (iii)

    (Large square factor) n is divisible by \(d^2\) for some \(d>L\).

  4. (iv)

    (Large smooth factor) n is divisible by some \(d \in \mathbb {N}_{\le L}\) with \(d > D\).

  5. (v)

    (Smooth times two nearby primes) \(n = d p_2 p_1\) where \(d \in \mathbb {N}_{\le L}\) and \(p_1,p_2\) are primes with \(\frac{R}{L} \le p_2 \le p_1 \le p_2 L\).

  6. (vi)

    (Integer times three nearby primes) \(n = d p_3 p_2 p_1\) where \(p_1,p_2,p_3\) are primes with \(\frac{R}{L^2} \le p_3 \le p_2 \le p_1 \le p_3 L^2\).

The primary set \(A_1\) is defined to be the set of all \(n \in [x]\) of the form

$$\begin{aligned} n = dp \end{aligned}$$

where \(d \in \mathbb {N}_{\le L}\) with \(d \le D\), p is a prime, and \(n > \frac{x}{L}\). The secondary set \(A_2\) is defined to be the set of all \(n \in [x]\) of the form

$$\begin{aligned} n = dps \end{aligned}$$

where p is a prime greater than L, \(d \in \mathbb {N}_{<p}\), and s is an almost prime (either a prime or product of two primes) whose prime factors all exceed pL.

Lemma 3.1

(Decomposition) If \(n \in [x]\), then n lies in at least one of \(A_1, A_2, E\). In other words, (3.7) (and hence (3.8)) holds.

Proof

We may assume that n avoids all the cases (i)–(vi) of E. Let \(p_1 \ge p_2 \ge p_3 \ge p_4\) be the four largest prime factors of n (with the convention that \(p_i=1\) if n has fewer than i prime factors). Since n avoids the cases (i), (ii) of E we have \(n > \frac{x}{L}\) and \(p_1 > R\). We divide into three cases.

  • If \(p_2 > \frac{p_1}{L}\), then we must have \(p_3 \le \frac{p_2}{L}\) (since n avoids case (vi) of E), and \(p_3 > L\) (since n avoids case (v) of E). We then have \(p_4 \ne p_3\) (since n avoids case (iii) of E). One then checks that one is in the set \(A_2\) (with \(p = p_3\), \(s = p_2 p_1\), and \(d = \frac{n}{p_1 p_2 p_3}\)).

  • If \(L < p_2 \le \frac{p_1}{L}\), then we must have \(p_3 \ne p_2\) (since n avoids case (iii) of E). One then checks that one is in the set \(A_2\) (with \(p=p_2\), \(s=p_1\), and \(d = \frac{n}{p_1 p_2}\)).

  • Finally, if \(p_2 \le L\), then the quantity \(d {:}{=}\frac{n}{p_1}\) is at most D (since n avoids case (iv) of E), and then one checks that one is in the set \(A_1\) (with \(p=p_1\)).

\(\square \)

Now we verify that the exceptional set E is small:

Proposition 3.2

(E small) We have \(\# E \ll \frac{x \log ^5_2 x}{\log ^2 x}\).

Proof

It suffices to show that the set of \(n \in [x]\) obeying each of the six cases (i)–(vi) of E has size \(O\left( \frac{x \log ^5_2 x}{\log ^2 x}\right) \).

The set of n obeying (i) clearly has size O(x/L), which is acceptable (with plenty of room to spare). By Lemma 1.5, the set of n obeying (ii) has size at mostFootnote 4

$$\begin{aligned} \sum _{n \in \mathbb {N}_{\le R}: n \le x} 1 \ll x^{1-\frac{1}{\log R}} \log R \end{aligned}$$

which is also acceptable (with room to spare) from (3.4). The set of n obeying (iii) has size at most

$$\begin{aligned} \sum _{L < d \le x^{1/2}} \frac{x}{d^2} \ll \frac{x}{L} \end{aligned}$$

which is again acceptable (with plenty of room to spare).

The set of n obeying (iv) has size at most

$$\begin{aligned} \sum _{d \in \mathbb {N}_{\le L}: d > D} \frac{x}{d}. \end{aligned}$$

Applying Lemma 1.5, we can bound this by

$$\begin{aligned} \ll x \frac{\log L}{D^{1/\log L}}, \end{aligned}$$

which is acceptable (with substantial room to spare) from (3.2), (3.3).

Now suppose that n obeys (v), thus

$$\begin{aligned} n = d p_2 p_1 \end{aligned}$$

where \(d \in \mathbb {N}_{\le L}\), and \(p_1, p_2\) are primes with

$$\begin{aligned} \frac{R}{L} \le p_2 \le p_1 \le \min \left( \frac{x}{d p_2}, p_2 L \right) . \end{aligned}$$

In particular \(p_2 \le \sqrt{\frac{x}{d}}\). We may also assume that \(d \le D\), since otherwise we are in case (iv).

By the prime number theorem (Lemma 1.6), we see that for any choice of \(d, p_2\), the number of possible values of \(p_1\) is at most

$$\begin{aligned} \ll \frac{1}{\log \frac{R}{L}} \min \left( \frac{x}{d p_2}, p_2 L\right) . \end{aligned}$$

We conclude that this contribution to the size is at most

$$\begin{aligned} \ll \frac{1}{\log \frac{R}{L}} \sum _{d \in \mathbb {N}_{\le L}: d \le D} \sum _{p_2 \le \sqrt{\frac{x}{d}}} \min \left( \frac{x}{d p_2}, p_2 L\right) . \end{aligned}$$

From the prime number theorem (Lemma 1.6) we have

$$\begin{aligned} \sum _{p_2 < \sqrt{\frac{x}{dL}}} p_2 L&\le L \sqrt{\frac{x}{dL}} \pi \left( \sqrt{\frac{x}{dL}} \right) \\&\ll L \frac{x}{dL} \frac{1}{\log \frac{x}{dL}} \\&\le \frac{1}{\log \frac{x}{DL}} \frac{x}{d} \end{aligned}$$

while from Lemma 1.7 we have

$$\begin{aligned} \sum _{\sqrt{\frac{x}{dL}} \le p_2 < \sqrt{\frac{x}{d}}} \frac{x}{dp_2} \ll \frac{\log L}{\log \frac{x}{DL}} \frac{x}{d} \end{aligned}$$

and so by we can bound the previous contribution to \(\# A_3\) by

$$\begin{aligned} \ll \frac{x \log L}{\log \frac{R}{L} \log \frac{x}{DL}} \sum _{d \in \mathbb {N}_{\le L}} \frac{1}{d} \end{aligned}$$

which byFootnote 5 Lemma 1.5 is bounded by

$$\begin{aligned} \ll \frac{x \log ^2 L}{\log \frac{R}{L} \log \frac{x}{DL}}. \end{aligned}$$

This is acceptable thanks to (3.2), (3.3), (3.4).

Finally, if n obeys (vi), then we may factor

$$\begin{aligned} n = d p_3 p_2 p_1 \end{aligned}$$

where \(p_1,p_2,p_3\) are primes in [x] with

$$\begin{aligned} \frac{R}{L^2} \le p_3 \le p_2 \le p_1 \le p_3 L^2. \end{aligned}$$

If we fix \(p_1,p_2,p_3\), there are at most \(\frac{x}{p_1 p_2 p_3}\) choices of d, thus this contribution to the size is at most

$$\begin{aligned} \sum _{\frac{R}{L^2} \le p_3 \le x} \sum _{p_2,p_1: p_3 \le p_2 \le p_1 \le p_3 L^2} \frac{x}{p_1 p_2 p_3}. \end{aligned}$$

By two applications of Lemma 1.7, this is

$$\begin{aligned} \ll \frac{x \log ^2(L^2)}{\log ^2(R/L^2)} \sum _{p_3 \le x} \frac{1}{p_3}, \end{aligned}$$

which is acceptable thanks to Mertens’ theorem and (3.4), (3.2). \(\square \)

We remark that one could obtain much sharper asymptotics on the size of E if desired using more sophisticated results from the anatomy of integers, such as [12].

Now we control \(A_2\).

Proposition 3.3

(\(A_2\) negligible) We have \(M(A_2) \ll \frac{x}{\log ^2 x}\).

Proof

Let \(A'\) be a subset of \(A_2\) on which \(\varphi \) is nondecreasing. Our task is to show that

$$\begin{aligned} \# A' \ll \frac{x}{\log ^2 x}. \end{aligned}$$

This will be the first time we will use the monotonicity of \(\varphi \) in our arguments; on the other hand, there is a lot of room here, and we can afford to lose several powers of \(\log x\) in what follows. If \(n \in A'\), then we may factor

$$\begin{aligned} n = d p s \end{aligned}$$

where p is a prime in the range

$$\begin{aligned} L < p \le x^{1/2}, \end{aligned}$$

d is an element of \(\mathbb {N}_{<p}\) with \(d \le \frac{x}{p^2\,L}\), and s is an almost prime, with all prime factors larger than pL. In particular

$$\begin{aligned} \varphi (s) = \left( 1 - O\left( \frac{1}{p L}\right) \right) s \end{aligned}$$

and thus by multiplicativity

$$\begin{aligned} \varphi (n)&= \varphi (d) \varphi (p) \varphi (s) \nonumber \\&= \frac{\varphi (d)}{d} \left( 1 - \frac{1 + O(\frac{1}{L})}{p}\right) n. \end{aligned}$$
(3.9)

We exploit this relation as follows. First we perform dyadic decomposition to estimate

$$\begin{aligned} \# A' \le \sum _{m: L< 2^m \ll x^{1/2}} \sum _{d \in \mathbb {N}_{<2^m}: d \ll \frac{x}{2^{2m}L} } a(m,d) \end{aligned}$$

where

$$\begin{aligned} a(m,d) {:}{=}\sum _{2^{m-1} < p \le 2^m} \sum _{s \le \frac{x}{dp}: dp s \in A'; (3.9)} 1 \end{aligned}$$

and the inner sum is restricted to those s for which \(n = dp s\) obeys the estimate (3.9). We will establish the estimate

$$\begin{aligned} a(m,d) \ll \frac{x}{d \log ^4 x} \end{aligned}$$
(3.10)

for each m with \(L < 2^m \ll x^{1/2}\) and all \(d \in \mathbb {N}_{<2^m}\); the claim will then follow by summing (3.10) over all dm and using crude estimates (or Lemma 1.5).

It remains to establish (3.10). We fix md. We cover the interval (1, x] by \(O(2^m\log ^6 x)\) consecutive disjoint intervals \(I_i\) of the form \(\Big (N, \Big (1 + \frac{1}{2^m \log ^5 x}\Big ) N\Big ]\) with \(1 \le N \ll x\). We similarly cover the interval \((2^{m-1}, 2^m]\) by \(O(\log ^4 x)\) consecutive disjoint intervals \(J_k\) of the form \(\Big (M, \Big (1 + \frac{1}{\log ^4 x}\Big )M\Big ]\) with \(M \asymp 2^m\). For each \(I_i\) and \(J_k\), let \(I_{i,k}\) be the smallest interval containing all the \(n \in I_i\) of the form \(n = dp s\), where ps contribute to (3.10) and \(p \in J_k\). (We allow \(I_{i,k}\) to be empty, or a single point.) Then we can bound

$$\begin{aligned} a(m,d) \le \sum _i \sum _k \sum _{p \in J_k} \sum _{s: dps \in I_{i,k}} 1. \end{aligned}$$
(3.11)

Since \(I_{i,k} \subset I_i\) and the \(I_i\) are disjoint, then \(I_{i,k}\) and \(I_{i',k'}\) are disjoint for \(i \ne i'\). Now we exploit the monotonicity of \(\varphi \) on \(A'\) via a key observation: if \(k' \ge k+2\), then \(I_{i,k'}\) lies strictly to the right of \(I_{i,k}\) (with the convention that this claim is vacuously true if at least one of \(I_{i,k}\), \(I_{i,k'}\) is empty). Indeed, suppose that \(n = d p s \in I_{i,k}\) and \(n' = d p' s' \in I_{i,k'}\) contribute to (3.10) with \(p \in J_k\) and \(p' \in J_{k'}\). From (3.9) we have

$$\begin{aligned} \varphi (n) = \frac{\varphi (d)}{d} \left( 1 - \frac{1 + O(\frac{1}{L})}{p}\right) n \end{aligned}$$

and

$$\begin{aligned} \varphi (n') = \frac{\varphi (d)}{d} \left( 1 - \frac{1 + O(\frac{1}{L})}{p'}\right) n' \end{aligned}$$

On the other hand, since \(n, n' \in I_i\) and \(p' \asymp 2^m\), we have

$$\begin{aligned} n' = \left( 1 + O\left( \frac{1}{p' \log ^5 x}\right) \right) n \end{aligned}$$

and thus (by (3.2))

$$\begin{aligned} \varphi (n') = \frac{\varphi (d)}{d} \left( 1 - \frac{1 + O(\frac{1}{\log ^5 x})}{p'}\right) n. \end{aligned}$$

Since \(p \in J_k\), \(p' \in J_{k'}\) and \(k' \ge k+2\) we have

$$\begin{aligned} p' \ge \left( 1 + \frac{1}{\log ^4 x}\right) p. \end{aligned}$$

Putting these estimates together (and recalling that x is assumed to be large), we conclude that

$$\begin{aligned} \varphi (n') > \varphi (n) \end{aligned}$$

and hence by monotonicity of \(\varphi \) on \(A'\) we have \(n' > n\). This gives the claim.

As a corollary of this monotonicity, we see that the intervals \(I_{i,k}\) have bounded overlap in [1, x] as ik vary (in fact any n can belong to at most two of the \(I_{i,k}\)). In particular,

$$\begin{aligned} \sum _i \sum _k |I_{i,k}| \ll x. \end{aligned}$$
(3.12)

We have theFootnote 6 trivial bound

$$\begin{aligned} \sum _{s: dp s \in I_{i,k}} 1 \ll \frac{|I_{i,k}|}{dp} + 1 \end{aligned}$$

and hence by (3.11) we may bound

$$\begin{aligned} a(m,d) \ll \sum _i \sum _k \sum _{p \in J_k} \left( \frac{|I_{i,k}|}{dp} + 1 \right) . \end{aligned}$$

Since there are only \(O(2^m \log ^6 x)\) values of i, and the \(J_k\) cover an interval \(\{ y: y \asymp 2^m\}\) with bounded overlap, we can crudely estimate

$$\begin{aligned} \sum _i \sum _k \sum _{p \in J_k} 1 \ll 2^{2m} \log ^6 x \end{aligned}$$

which since \(d \ll \frac{x}{2^{2m} L}\) implies that

$$\begin{aligned} \sum _i \sum _k \sum _{p \in J_k} 1 \ll \frac{x}{d} \frac{\log ^6 x}{L}. \end{aligned}$$

Next, by discarding the requirement that p is prime, we have the trivial bound

$$\begin{aligned} \sum _{p \in J_k} 1 \ll \frac{2^m}{\log ^4 x} + 1; \end{aligned}$$

since \(p \asymp 2^m > L\) for \(p \in J_k\), we conclude

$$\begin{aligned} \sum _{p \in J_k} \frac{1}{dp} \ll \frac{1}{d} \left( \frac{1}{\log ^4 x} + \frac{1}{L} \right) . \end{aligned}$$

By (3.12), we conclude that

$$\begin{aligned} \sum _i \sum _k \sum _{p \in J_k} \frac{|I_{i,k}|}{dp} \ll \frac{x}{d} \left( \frac{1}{\log ^4 x} + \frac{1}{L} \right) . \end{aligned}$$

Combining these estimates, we obtain

$$\begin{aligned} a(m,d) \ll \frac{x}{d} \left( \frac{1}{\log ^4 x} + \frac{\log ^6 x}{L} \right) \end{aligned}$$

and (3.10) follows from (3.2). \(\square \)

Finally, we treat the primary set \(A_1\).

Proposition 3.4

(\(A_1\) contribution) We have \(M(A_1) \le \left( 1 + O\left( \frac{\log _2 x}{\log x} \right) \right) \frac{x}{\log x}\).

Proof

Let \(A'\) be a subset of \(A_1\) on which \(\varphi \) is nondecreasing. Our task is to show that

$$\begin{aligned} \# A' \le \left( 1 + O\left( \frac{\log _2 x}{\log x} \right) \right) \frac{x}{\log x}. \end{aligned}$$
(3.13)

If \(n \in A'\), then we may factor

$$\begin{aligned} n = dp \end{aligned}$$

where \(d \in \mathbb {N}_{\le L}\) with

$$\begin{aligned} d \le D \end{aligned}$$
(3.14)

and p is a prime which then lies in the range

$$\begin{aligned} \frac{x}{DL} \le p \le \frac{x}{d}. \end{aligned}$$
(3.15)

In particular (from (3.3)) we certainly have

$$\begin{aligned} p \ge D^3. \end{aligned}$$
(3.16)

Thus p is coprime to d, and hence

$$\begin{aligned} \varphi (n)&= \varphi (d) \varphi (p)\nonumber \\&= \frac{\varphi (d)}{d} \left( 1 - \frac{1}{p} \right) n. \end{aligned}$$
(3.17)

If we define the set

$$\begin{aligned} {{\mathcal {Q}}} {:}{=}\left\{ \frac{\varphi (d)}{d}: d \in \mathbb {N}_{\le L}; d \le D \right\} \end{aligned}$$

then \({{\mathcal {Q}}}\) is a finite set of rationals in (0, 1], of some cardinality \(K = \# {{\mathcal {Q}}}\) with

$$\begin{aligned} K \le D. \end{aligned}$$
(3.18)

We arrange the elements of \({{\mathcal {Q}}}\) in increasing order as

$$\begin{aligned} 0< q_1< q_2< \cdots < q_K \le 1. \end{aligned}$$

For each \(k=1,\ldots ,K\), we let \({{\mathcal {D}}}_k\) denote the set of all \(d \in \mathbb {N}_{\le L}\) with \(d \le D\) and

$$\begin{aligned} \frac{\varphi (d)}{d} = q_k. \end{aligned}$$
(3.19)

We also partition \(\big [\frac{x}{L}, x\big ]\) into \(O(D^3 \log L)\) disjoint intervals \(I_i\) of the form \(\big (N, \big (1+O\big (\frac{1}{D^3}\big )\big ) N\big ]\). For \(k=1,\ldots ,K\), and any i, let \(I_{i,k}\) denote the smallest interval containing all \(n=dp\) in \(A' \cap I_i\) with \(d \in {{\mathcal {D}}}_k\) and p a prime obeying (3.15). Then we have

$$\begin{aligned} \# A' \le \sum _i \sum _{k=1}^K \sum _{d \in {{\mathcal {D}}}_k} \sum _{p: d p \in I_{i,k}} 1. \end{aligned}$$
(3.20)

The key observation is that the intervals \(I_{i,k}\) are all disjoint. To see this, first observe that since \(I_{i,k} \subset I_i\) and the \(I_i\) are disjoint, we clearly have \(I_{i,k} \cap I_{i',k'} = \emptyset \) if \(i \ne i'\). Next, we claim that if \(1 \le k < k' \le K\) then \(I_{i,k'}\) lies strictly to the right of \(I_{i,k}\) (so in particular the two sets are disjoint). Indeed, if \(n = d p \in I_{i,k}\) and \(n' = d' p' \in I_{i,k'}\) then from (3.17), (3.16), (3.19) one has

$$\begin{aligned} \varphi (n) = \frac{\varphi (d)}{d} \left( 1 - \frac{1}{p}\right) n = q_k \left( 1 - O\left( \frac{1}{D^3}\right) \right) n. \end{aligned}$$

Similarly we have

$$\begin{aligned} \varphi (n') = q_{k'}\left( 1 - O\left( \frac{1}{D^3}\right) \right) n'. \end{aligned}$$

Also, as \(n,n'\) both lie in \(I'\), we have

$$\begin{aligned} n' = \left( 1 + O\left( \frac{1}{D^3}\right) \right) n, \end{aligned}$$

while since \(k' > k\), we have \(q_{k'} > q_k\). From (3.14), the rational numbers \(q_{k'}, q_k\) have denominator at most D, hence

$$\begin{aligned} q_{k'} - q_k \ge \frac{1}{D^2} \end{aligned}$$

and thus (since \(q_k \le 1\))

$$\begin{aligned} q_{k'} \ge \left( 1 + \frac{1}{D^2}\right) q_k. \end{aligned}$$

Combining all these statements (and recalling that x and hence D is large), we conclude that

$$\begin{aligned} \varphi (n') > \varphi (n) \end{aligned}$$

and hence \(n' > n\) by monotonicity, giving the claim.

From the prime number theorem (Lemma 1.6) and (3.15) we have

$$\begin{aligned} \sum _{p: d p \in I_{i,k}} 1&\le \int _{\frac{1}{d} I_{i,k}} \frac{\textrm{d}t}{\log t} + O\left( \frac{x}{d} \exp \left( -c \sqrt{\log \frac{x}{d}}\right) \right) \\&\le \left( 1 + O\left( \frac{\log (DL)}{\log x} \right) \right) \frac{|I_{i,k}|}{d \log x} + O\left( \frac{x}{d} \exp \left( -c \sqrt{\log \frac{x}{D}}\right) \right) \end{aligned}$$

for an absolute constant \(c>0\). From Lemma 1.4 we have the crucial inequality

$$\begin{aligned} \sum _{d \in {{\mathcal {D}}}_k} \frac{1}{d} \le 1. \end{aligned}$$

Inserting these bounds back into (3.20), we conclude that

$$\begin{aligned} \# A' \le \left( 1 + O\left( \frac{\log (DL)}{\log x} \right) \right) \sum _i \sum _{k=1}^K \frac{|I_{i,k}|}{\log x} + O\left( \sum _i \sum _{k=1}^K x \exp \left( -c \sqrt{\log \frac{x}{D}}\right) \right) . \end{aligned}$$

From disjointness of the \(I_{i,k}\) we have

$$\begin{aligned} \sum _i \sum _{k=1}^K |I_{i,k}| \le x. \end{aligned}$$

Since there are \(O(D^3 \log L)\) values of i, we conclude

$$\begin{aligned} \# A' \le \left( 1 + O\left( \frac{\log (DL)}{\log x} \right) \right) \frac{x}{\log x} + O\left( x K D^3 (\log L) \exp \left( -c \sqrt{\log \frac{x}{D}}\right) \right) \end{aligned}$$

and (3.13) follows from (3.18), (3.2), (3.3). \(\square \)

Inserting Propositions 3.2-3.4 into (3.8), we obtain Theorem 1.1 as claimed.

4 Obstacles to Improvement, Variants, and Open Questions

It seems likely that small improvements to Theorem 1.1, such as the lowering of the exponent 5 in the power of \(\log _2 x\), could be achieved with minor modifications of the method. However, we now present two obstacles that seem to prevent one from unconditionally establishing significantly stronger results, such as (1.3), and pose some open problems that might still be achievable despite these obstacles.

4.1 Legendre Conjecture Obstruction

Legendre’s conjecture asserts that for every \(n \ge 2\), there is a prime between \((n-1)^2\) and \(n^2\). This conjecture remains open even for sufficiently large n, and even if one assumes the Riemann hypothesis (RH); it is roughly equivalent to showing that the gap \(p_{n+1}-p_n\) between consecutive primes is significantly smaller than \(p_n^{1/2}\), whereas the best known bound is \(O(p_n^{1/2} \log p_n)\) on RH [4], or \(O(p_n^{0.525})\) unconditionally [2]. On the other hand, this conjecture is implied by the Cramér conjecture \(p_{n+1}-p_n \ll \log ^2 p_n\) [4]; it has also been verified for \(n \le 2 \times 10^9\) [20].

Legendre’s conjecture is also open if one restricts n to be prime. This special case of the conjecture will need to be resolved if one wishes to establish (1.3), due to the following implication:

Proposition 4.1

Suppose that Legendre’s conjecture is false for infinitely many primes; that is to say, there exist infinitely many primes p such that there is no prime between \((p-1)^2\) and \(p^2\). Then \(M(x) - \pi (x)\) goes to infinity as \(x \rightarrow \infty \).

Stated contrapositively: if (1.3) holds, then Legendre’s conjecture is true for all sufficiently large primes.

Proof

If p is a prime counterexample to Legendre’s conjecture, then for primes \(p'\) larger than \(p^2\) we have

$$\begin{aligned} \varphi (p') = p'-1 \ge p^2 > \varphi (p^2) \end{aligned}$$

and for primes \(p'\) less than \(p^2\), we have \(p' < (p-1)^2\) and hence

$$\begin{aligned} \varphi (p')< p'< (p-1)^2 < p^2-p = \varphi (p^2). \end{aligned}$$

Thus one can insert \(p^2\) into the sequence of primes without disrupting the monotonicity of \(\varphi \). If there are infinitely many counterexamples to Legendre’s conjecture at the primes, then one can then insert an infinite number of additional elements into the primes to create a larger sequence with \(\varphi \) nondecreasing, giving the claim. \(\square \)

Remark 4.2

One can replace Legendre’s conjecture here with the very slightly stronger conjecture of Oppermann [21] that there is always a prime between \(n(n-1)\) and \(n^2\) for \(n \ge 3\). (Oppermann also made the analogous conjecture concerning \(n^2\) and \(n(n+1)\), but that is of less relevance here.)

Remark 4.3

With a little more computation, one can show that the conjecture (1.4) implies that Legendre’s conjecture holds at all primes (not just sufficiently large ones).

Remark 4.4

In [26], the estimate

$$\begin{aligned} \sum _{n \le x} \frac{(p_{n+1}-p_n)^2}{p_n} \ll \log ^3 x \end{aligned}$$

is proven for large x assuming the Riemann hypothesis, where \(p_n\) denotes the \(n^{\textrm{th}}\) prime. One consequence of this is that the counterexamples to Legendre’s conjecture are quite rare on RH, since each such counterexample contributes \(\gg 1\) to this sum. Thus this obstruction only worsens the gap between M(x) and \(\pi (x)\) by at most \(O(\log ^3 x)\), on RH.

4.2 Dickson–Hardy–Littlewood Conjecture Obstruction

The Dickson–Hardy–Littlewood conjecture [6, 15] asserts, among other things, that if ab are coprime integers with \(a>0\), that the number of primes \(p \in [x]\) with \(ap+b\) also prime is equal to

$$\begin{aligned} ({\mathfrak S}_{a,b} + o(1)) \frac{x}{\log ^2 x} \end{aligned}$$

as \(x \rightarrow \infty \) for some positive quantity \({\mathfrak S}_{a,b}\) (known as the singular series) which has an explicit form which we will not give here. Among other things, this conjecture (together with standard bounds for averages of singular series) would imply for any fixed natural number k that the number of primes \(p \in [x]\) such that the quantity \(\lceil \frac{p}{2^k} \rceil \) (the first integer greater than or equal to \(p/2^k\)) is also prime is \(\asymp \frac{x}{\log ^2 x}\), if x is sufficiently large depending on k. Such results are out of reach of current technology; note for instance that the Dickson–Hardy–Littlewood conjecture implies the notoriously open twin prime conjecture.

The following result shows that a severe breakdown of the Dickson–Hardy–Littlewood conjecture would imply that the bounds in Theorem 1.1 cannot be improved (except perhaps for removing the factors of \(\log _2 x\)).

Proposition 4.5

Suppose that for all sufficiently large x, and all natural numbers k with \(2^k \le 2\log x\), that the number of primes \(p \in [x]\) with \(\lceil \frac{p}{2^k} \rceil \) also prime is bounded by \(O\bigg (\frac{x}{\log ^2 x \log ^3_2 x}\bigg )\) (in contradiction with what the Dickson–Hardy–Littlewood conjecture would predict). Then one has

$$\begin{aligned} M(x) - \pi (x) \gg \frac{x}{\log ^2 x} \end{aligned}$$

for sufficiently large x.

This proposition suggests that significant progress on the Dickson–Hardy–Littlewood conjecture would need to be made in order to improve the error term in Theorem 1.1 to be better than \(O\big (\frac{1}{\log x}\big )\); in particular, this would need to be accomplished in order to have any hope of establishing (1.3). Note that standard probabilistic heuristics (cf. [14]) predict that for \(2^k \le 2 \log x\), a positive fraction of the intervals \([n, n+2^k]\) in [x] will be devoid of primes, and so the set \(\{ \lceil \frac{p}{2^k} \rceil : p \in [x] \}\) should avoid a positive density subset of \([x/2^k]\). Thus, in the absence of the Dickson–Hardy–Littlewood conjecture it is a priori conceivable that the primes in \([x/2^k]\) mostly avoid such a set; we do not know how to rule out such a scenario with current technology. We remark that the Maynard sieve [19, Theorem 3.1] (when combined with the calculations in [23]; see also [13, Lemma 2]) applied to the linear functions \(n \mapsto 2^j n + 1\) for \(j=1,\ldots ,50\) implies that there exists \(1 \le k \le 49\) such that the number of primes p in [x] with \(\lceil \frac{p}{2^k} \rceil \) also prime is \(\gg \frac{x}{\log ^{50} x}\) for infinitely many x, but this bound is not strong enough to contradict the hypothesis of the above proposition.

Proof

The construction here is motivated by the observation (see Remark 2.2) that Proposition 1.4 holds with equality not only at \(q=1\), but also at \(q=\frac{1}{2}\), as well as the construction discussed after Proposition 1.4 in the introduction. We thank Kevin Ford for pointing out an improvement to the argument that gave superior quantitative bounds.

Let x be sufficiently large, and let \(k_0\) be the unique natural number with

$$\begin{aligned} \log x < 2^{k_0} \le 2 \log x. \end{aligned}$$

Let A be the set of all numbers \(n \in [x]\) of the form \(n = 2^k p\) where \(1 \le k \le k_0\) and p is an odd prime. Observe from the prime number theorem (Lemma 1.6) and the logarithmic integral asymptotic

$$\begin{aligned} \int _2^x \frac{\textrm{d}t}{\log t} = \frac{x}{\log x} + \frac{x}{\log ^2 x} + O\left( \frac{x}{\log ^3 x}\right) \end{aligned}$$

followed by Taylor expansion that

$$\begin{aligned} \# A&= \sum _{k=1}^{k_0} (\pi (x/2^k) - 1) \\&= \sum _{k=1}^{k_0} \left( \frac{x/2^k}{\log (x/2^k)} + \frac{x/2^k}{\log ^2(x/2^k)} + O\left( \frac{x/2^k}{\log ^3(x/2^k)} \right) \right) \\&= \sum _{k=1}^{k_0} \left( \frac{x}{2^k(\log x - k \log 2)} + \frac{x}{2^k(\log x - k \log 2)^2} + O\left( \frac{x}{2^k \log ^3 x} \right) \right) \\&= \sum _{k=1}^{k_0} \left( \frac{x}{2^k \log x} + \frac{(1 + k \log 2) x}{2^k \log ^2 x} + O\left( \frac{k^2 x}{2^k \log ^3 x} \right) \right) . \end{aligned}$$

We have \(k_0 = O(\log _2 x)\),

$$\begin{aligned} \sum _{k=1}^{k_0} \frac{1}{2^k} = 1 - \frac{1}{2^{k_0}} \ge 1 - \frac{1}{\log x} \end{aligned}$$

and

$$\begin{aligned} \sum _{k=1}^{k_0} \frac{k}{2^k} = 2 - O\left( \frac{k_0}{2^{k_0}} \right) = 2 - O\left( \frac{\log _2 x}{\log x} \right) \end{aligned}$$

and thus

$$\begin{aligned} \# A \ge \frac{x}{\log x} + \frac{x \log 4}{\log ^2 x} - O\left( \frac{x \log _2 x}{\log ^3 x} \right) . \end{aligned}$$
(4.1)

Note for comparison that

$$\begin{aligned} \pi (x) = \frac{x}{\log x} + \frac{x}{\log ^2 x} + O\left( \frac{x}{\log ^3 x} \right) . \end{aligned}$$

Since \(\log 4 > 1\), we see that A is slightly denser than the primes.

Unfortunately, \(\varphi \) is not quite nondecreasing on A; however, the exceptions to monotonicity are quite rare and can be described explicitly as follows. Suppose that \(2^k p\), \(2^{k'} p'\) are elements of A with \(2^k p < 2^{k'} p'\) and \(\varphi (2^k p) > \varphi (2^{k'} p')\). Evaluating the totient functions, we obtain

$$\begin{aligned} 2^{k-1} (p-1) > 2^{k'-1} (p'-1) \end{aligned}$$

which we can rearrange as

$$\begin{aligned} 2^{k'} p' - 2^k p < 2^{k'} - 2^k. \end{aligned}$$

Since the left-hand side is positive, we must then have \(k' > k\). Dividing by \(2^{k'}\), we conclude in particular that

$$\begin{aligned} \frac{p}{2^{k'-k}}< p' < \frac{p}{2^{k'-k}}+1 \end{aligned}$$

and thus

$$\begin{aligned} p' = \big \lceil \frac{p}{2^{k'-k}} \big \rceil . \end{aligned}$$

By hypothesis, this scenario can only occur for \(O\Big (\frac{x}{\log ^2 x \log ^3_2 x}\Big )\) primes p for each choice of \(k,k'\). Since there are at most \(O(\log _2^2 x)\) choices for \(k,k'\), we thus see that by deleting at most \(O\Big (\frac{x}{\log ^2 x \log _2 x}\Big )\) elements from A, one can obtain a slightly smaller set \(A'\) that still obeys the asymptotic (4.1), but on which \(\varphi \) is now nondecreasing. Since

$$\begin{aligned} \# A' - \pi (x) \gg \frac{x}{\log ^2 x} \end{aligned}$$

for sufficiently large x, we obtain the claim. \(\square \)

4.3 A Conditional Result?

Despite these two obstructions, it is possible that a more refined version of the analysis in this paper can be used to show that a significant improvement to the bounds in Theorem 1.1 can be achieved unless one of the above two scenarios occurs (breakdown of Legendre-type conjectures, or breakdown of Dickson–Hardy–Littlewood type conjectures). Indeed, the fact (see Remark 2.2) that Lemma 1.4 gains a factor of two when \(q \ne 1, \frac{1}{2}\) implies (by a routine modification of the arguments in this paper) that, if one sets A to be the elements of [x] that are not a prime, or a power of two times a prime, then \(M(A) \le \big (\frac{1}{2} + O\big ( \frac{\log _2^5 x}{\log x} \big )\big ) \pi (x)\). Thus largest subsets of [x] on which \(\varphi \) are increasing must have almost half or more of their elements consist of primes, or powers of two times a prime. With a suitable form of the Dickson–Hardy–Littlewood conjectures, one might be able to show that the sets which contain a large number of powers of two times a prime lead to a set with fewer than \(\pi (x)\) elements, and so one would be left with studying sets that largely consist of primes. Here, one could take advantage of the phenomenon (already observed in [22, Sect. 9]) that for any prime p, the first composite number \(n > p\) with \(\varphi (n) \ge \varphi (p)\) must in fact exceed \(p + \sqrt{p} - 1\), which suggests that (in the absence of extremely large prime gaps, as in Proposition 4.1), it could rule out competitors to the set of primes in which one or more primes in the “interior” of the set are replaced with composite numbers. In view of known results on the anatomy of integers in short intervals, one might hope to obtain a bound such as \(M(x) = \pi (x) + O( x^\theta )\) for some \(0< \theta < 1\) assuming additional conjectures, such as a sufficiently quantitative version of the Dickson–Hardy–Littlewood conjecture. In a closely related spirit, one could also seek to obtain a “short interval” version of the main theorem of the form

$$\begin{aligned} M( [x + x^\theta ] \backslash [x] ) \le (1+o(1)) (\pi (x+x^\theta ) - \pi (x)) \end{aligned}$$

for some \(0< \theta < 1\).

4.4 Analogues for the Sum of Divisors Function

It turns out (as already conjectured in [10]) that the Euler totient function \(\varphi (n)\) may be replacedFootnote 7 by the sum of divisors function \(\sigma (n) {:}{=}\sum _{d|n} d\) throughout the above arguments. The main difficulty is to obtain an analogue

$$\begin{aligned} \sum _{\frac{\sigma (d)}{d} = q} \frac{1}{d} \le 1 \end{aligned}$$
(4.2)

of Proposition 1.4 for the sum of divisor function, since there is no analogue of Lemma 2.1. For instance, \(\sum _{\frac{\sigma (d)}{d} = 2} \frac{1}{d}\) is the sum of reciprocals of perfect numbers, for which there are notorious open questions (for instance, it is still open whether there are infinitely many perfect numbers), though in this case \(q=2\) the sum in (4.2) is known to equal \(0.204520\ldots \) [3, Theorem 7]. On the other hand, the weaker bound

$$\begin{aligned} \sum _{\frac{\sigma (d)}{d} = q} \frac{1}{d} \ll 1 \end{aligned}$$

was observedFootnote 8 in [9, p. 63] to follow from the estimate claimed in [8, Theorem 3] (see also [7, pp. 212–213] for an alternate proof). In [9, p. 63] it was also claimed that (4.2) could be shown “with more trouble”, but without a full proof provided. Such problems are also related to those of counting solutions to \(\sigma (n)=\sigma (n+k)\) for fixed k; see [13]. Since the initial release of this preprint, a full proof of (4.2) using the methods in [8] has been kindly provided to us (via the author’s personal blog) by Shengtong Zhang, which we reproduce below. Given this inequality, the arguments in Sect. 3 can be modified as follows in order to obtain the analogue of Theorem 1.1 for the sum of divisors function:

  • All occurrences of \(\varphi \) should now be replaced with \(\sigma \) (including in the definition of M()).

  • In the proof of Proposition 3.3, all displayed expressions of the form \(1 - \frac{\dots }{p}\) should be replaced with \(1 + \frac{\dots }{p}\) (and similarly with p replaced by \(p'\)), and “\(I_{i,k'}\) lies strictly to the right of \(I_{i,k}\)” should be replaced with “\(I_{i,k'}\) lies strictly to the left of \(I_{i,k}\)”.

  • In the proof of Proposition 3.4, all displayed expressions of the form \(1 - \frac{1}{p}\) or \(1 - O\big (\frac{1}{D^3}\big )\) should be replaced with \(1 + \frac{1}{p}\) or \(1 + O\big (\frac{1}{D^3}\big )\) respectively, and Proposition 1.4 must be replaced with (4.2).

In particular, the largest subset of [x] on which \(\sigma \) is nondecreasing has cardinality \(\left( 1+O\left( \frac{\log _2^5 x}{\log x}\right) \right) \pi (x)\).

Now we present Zhang’s proof of (4.2). We may assume that \(q \ne 1\), since the only solution to \(\frac{\sigma (d)}{d}=1\) is \(d=1\). We split any natural number d with \(\frac{\sigma (d)}{d}=q\) uniquely into a product \(d = \gamma s\) of a powerful number \(\gamma \) (a number which is not divisible precisely once by any prime) and a squarefree number s coprime to \(\gamma \). The key observation (a minor variant of the lemma in [8, p. 173]) is that for fixed q, the squarefree number s is determined by \(\gamma \). Indeed, suppose we had two numbers \(d = \gamma s\), \(d' = \gamma s'\) with \(\frac{\sigma (d)}{d} = \frac{\sigma (d')}{d'} = q\) with \(s \ne s'\) squarefree and coprime to \(\gamma \). Then by multiplicativity we have

$$\begin{aligned} \frac{\sigma (s)}{s} = \frac{\sigma (s')}{s'}. \end{aligned}$$

If we let \(a {:}{=}s/(s,s')\), \(a' = s'/(s,s')\), then \(a,a'\) are coprime and square-free with

$$\begin{aligned} \frac{\sigma (a)}{a} = \frac{\sigma (a')}{a'}. \end{aligned}$$
(4.3)

If \(a=1\) then \(a'=1\) and hence \(s=s'\), contradiction, and similarly if \(a'=1\). Thus we may assume \(a,a' > 1\). At least one of \(a,a'\) is not divisible by 3, so without loss of generality we may assume that a is not divisible by 3. Then the largest prime factor of a divides a but not \(a'\) or \(\sigma (a)\), contradicting (4.3), and the key observation follows.

We may thus write

$$\begin{aligned} \sum _{\frac{\sigma (d)}{d}=q} \frac{1}{d} = \sum _\gamma \frac{1}{\gamma s_\gamma } \end{aligned}$$

where \(\gamma \) ranges over powerful numbers, and \(s_\gamma = s_{\gamma ,q}\) is equal to the (necessarily unique) square-free number coprime to \(\gamma \) with \(\frac{\sigma (\gamma s_\gamma )}{\gamma s_\gamma } = q\), or \(s_\gamma {:}{=}+\infty \) if no such number exists. Since every powerful number is the product of a square and a cube, we have

$$\begin{aligned} \sum _\gamma \frac{1}{\gamma } \le \zeta (2) \zeta (3) = 1.97730\dots < 2 \end{aligned}$$

(in fact the sum is equal to \(\zeta (2) \zeta (3)/\zeta (6) = 1.94359\dots \)). This already establishes (4.2) but with an upper bound of 2 instead of 1. To refine the upper bound to 1, it will suffice to establish the lower bound

$$\begin{aligned} \sum _\gamma \frac{1}{\gamma } \left( 1 - \frac{1}{s_\gamma }\right) \ge 1. \end{aligned}$$

Since the summand is non-negative, it will suffice to establish this bound for the powers of 2, thus we have reduced to showing that

$$\begin{aligned} 1 - \frac{1}{s_1} + \sum _{j=2}^\infty \frac{1}{2^j} \left( 1 - \frac{1}{s_{2^j}}\right) \ge 1. \end{aligned}$$
(4.4)

This can be verified by the following case analysis.

  • The case \(s_1=1\) cannot occur since q is assumed to not equal 1.

  • If \(s_1=2\), then \(q = \frac{\sigma (2)}{2}=\frac{3}{2}\), but then \(s_{2^j}=\infty \) for \(j \ge 2\) since \(\frac{\sigma (2^j s)}{2^j s} \ge \frac{2^{j+1}-1}{2^j} > \frac{3}{2}\) for any \(j \ge 2\) and s coprime to j, and so the left-hand side of (4.4) is \(1 - \frac{1}{2} + \sum _{j=2}^\infty \frac{1}{2^j} = 1\).

  • If \(s_1=\infty \), then the left-hand side of (4.4) is clearly at least \(1 - \frac{1}{s_1}=1\).

  • Finally, if \(3 \le s_1 < \infty \), then \(q = \frac{\sigma (s_1)}{s_1}\) has a squarefree denominator, which implies for any \(j \ge 2\) and s coprime to \(2^j\) that \(\frac{\sigma (2^j)}{2^j} = \frac{2^{j+1}-1}{2^j}\) is not equal to q (the denominator is divisible by \(2^2\)). Hence \(s_{2^j}\) cannot equal 1, and must therefore be at least 3 since \(s_{2^j}\) must be coprime to \(2^j\). Thus the left-hand side of (4.4) is at least \(1 - \frac{1}{3} + \sum _{j=2}^\infty \frac{1}{2^j} \big (1-\frac{1}{3}\big ) = 1\).

Remark 4.6

The argument in fact shows that equality in (4.2) can only occur when \(q=1\), so in some sense the situation with \(\sigma \) is slightly better than that with \(\varphi \) (in which \(q=1/2\) is also an equality case). A variant of the above argument also shows that for any \(\varepsilon >0\), there are only finitely many q for which the sum \(\sum _{\frac{\sigma (d)}{d}=q} \frac{1}{d} \ge \varepsilon \) (because one must have \(s_\gamma \ll \frac{1}{\varepsilon }\) for some powerful \(\gamma \ll _\varepsilon 1\)).

Remark 4.7

Analogous results also hold when \(\phi \) or \(\sigma \) is replaced byFootnote 9 the Dedekind totient function

$$\begin{aligned} \psi (n) {:}{=}n \prod _{p|n} \frac{p+1}{p}. \end{aligned}$$

Again, the main difficulty is to establish an analogue of Proposition 1.4 for this function. The proof of Lemma 2.1 almost works for \(\psi \) with only obvious modifications; however, due to the presence of the consecutive primes 2, 3, there is one exception to the assertion that when

$$\begin{aligned} \frac{\psi (d)}{d} = \prod _{p|d} \frac{p+1}{p} \end{aligned}$$

is expressed in lowest terms as \(\frac{a}{b}\), that the largest prime factor of b is that of d. Namely, when the prime factors of d are precisely 2 and 3, then there is a cancellation

$$\begin{aligned} \frac{\psi (d)}{d} = \frac{2+1}{2} \frac{3+1}{3} = \frac{2}{1} \end{aligned}$$

and the largest prime factor of b is now (by our convention) 1 instead of 3. However, because 2, 3 are the only pair of consecutive primes, this is the unique exception to the above assertion. As a consequence, it is possible to modify the inductive argument used to establish Lemma 2.1 to prove an analogue for \(\psi \), with the one modification that if \(q = \frac{2}{1}\), then the largest element of \({{\mathcal {P}}}\) is equal to 3 rather than \({{\mathcal {P}}}\) being empty. (For this, it is convenient to take the base case to be the case when the largest prime factor of b is at most 3, which can be handled by a finite case analysis.) The rest of the arguments then continue as before with only obvious modifications; we leave the details to the interested reader.