In order to solve this, we will give a complete classification of n-sequences.
Let k=⌊n/2⌋. We will say that an n-sequence is large if ai>k for some i, and small if no such i exists. For now we will assume that (ai) is not the identity sequence (in other words, that ai=i for some i).
Lemma 1. If ar=as and r,s<n, then ar+1=as+1.
Proof. We have ar+1=aar+a1=aas+a1=as+1.
Lemma 2. If i⩽k, then ai⩽k.
Proof. We have i+i⩽n, so ai+ai⩽n whence ai⩽k.
Lemma 3. There exist r,s such that ar=as and r=s.
Proof. If a0=0 then a2a0=a0. Otherwise, aai=ai for all i, so take i such that ai=i (which we can do by our earlier assumption).
Lemma 4. Let r be the smallest index such that as=ar for some s>r, and let d be the minimum positive integer such that ar+d=ar. Then
1. The subsequence (ar,ar+1,…,an) is periodic with minimal period d. That is, for u<v, we have au=av if and only if u,v⩾r and d∣v−u.
2. ai=i for i<r and ai⩾r for i⩾r.
In this case we say (ai) has period d and offset r.
Proof. We prove each in turn:
1. The "if" implication is clear from Lemma 1. For the reverse direction, suppose au=av. Then there are integers r⩽u0,v0<r+d such that d∣u−u0,v−v0, so au0=au=av=av0. If u0<v0 then ar+d+u0−v0=ar+d=ar, contradicting the minimality of d. There is a similar contradiction when u0>v0. Thus u0=v0, so d∣u−v.
2. If r=0 there is nothing to prove. Otherwise a0=a2a0 so 2a0=0. Then we have aai=ai for all i, so ai=i for i<r.
Lemma 5. Either
1. d∣ai−i for all i, or
2. r=0 and d∣ai−i−d/2 for all i.
Proof. Note that Lemma 4 tells us that if au=av then d∣u−v. Since aai+a0=ai for all i, we have d∣ai−i+a0. For i=0, this means that d∣2a0. If d∣a0 then that means that d∣ai−i for all i. Otherwise, if d∤a0, then d∣a0−d/2 and thus d∣ai−i−d/2 for all i. In addition, part 2 of Lemma 4 says that we must have r=0 in this case.
Lemma 6. If d is even and d∣a0−d/2, then (ai) is small. (Note that we must have r=0 in this case.)
Proof. Note that if d⩽k+1, then by Lemma 2, (a0,…,ad−1) is a period for the sequence consisting of elements at most k, so (ai) must be small. Now suppose d>k+1. We show that ai⩽k for all i by induction. Note that Lemma 2 already establishes this for i⩽k. We must have d∣ad/2 and ad/2⩽k<d so ad/2=0. Thus, for i>k, if aj⩽k for j<i, then ai−d/2⩽k, so ai=a(i−d/2)+d/2=aai−d/2⩽k.
Lemma 7. If (ai) is small, then r+d⩽k+1.
Proof. Since (ai) is small, there exists u,v⩽k+1 such that u<v and au=av. Thus u⩽r and d∣v−u, so r+d⩽v⩽k+1.
Lemma 8. If (ai) is large, then r+d>k+1 and ai=i for all 0⩽i<r+d.
Proof. Since (ai) is large and has period d and offset r, the period (ar,…,ar+d−1) must have an element that is larger than k, so by Lemma 2 we must have r+d−1>k.
We already have ai=i for i<r. Now we show that ai=i for r⩽i⩽k. By Lemma 6 we have d∣ai−i but r⩽i⩽k. Since k−r+1>d, this means that ai=i for i⩽k.
Finally, one can show inductively that ai=i for k<i<r+d. Indeed, if aj=j for all j<i, then ai⩾i (otherwise ai=aj for some j<i, but then r⩽j and i<r+d means that d∤j−i.) However, ai+(n−i)=ai+an−i⩽n, so ai=i.
Thus large sequences are determined by r and d. It is not hard to check that all sequences of the form ai=i for i<r+d and with period d and offset r are n-sequences. There are (n−k−1)(n+k+2)/2 possible choices of (r,d) where 0⩽r<n,d⩾1, and k+1<r+d⩽n.
For small sequences, for a given period d and offset r, we need to choose the period (ar,…,ar+d−1) satisfying r⩽aj⩽k and d∣aj−j for r⩽j<r+d. There are g(k+1−r,d) such choices, where we define g(x,d) to be (p+1)qpd−q with p=⌊x/d⌋ and q=x−dp.
Furthermore, if d is even then there are g(k+1,d) choices for the period (a0,…,ad−1) satisfying d∣aj−j−d/2 for j<d. Again it is not hard to check that, once these choices are made, then the resulting sequence is an n-sequence.
Thus the total number of n-sequences is
f(n)=1+2(n−k−1)(n+k+2)+d′=1∑⌊(k+1)/2⌋g(k+1,2d′)+r=0∑kd=1∑k+1−rg(k+1−r,d)(1)
Now, to show that f(n)>c1λn for some c1, we note that
f(n)>g(k+1,⌊3k+1⌋)⩾3⌊(k+1)/3⌋>3n/6−1.
To show that f(n)<c2λn for some c2, it actually suffices to show that there is a positive real number c3 such that for all positive integers x,
d=1∑xg(x,d)⩽c33x/3
In fact, the following lemma suffices, as it bounds the left hand side of the above inequality by a pair of geometric series with initial term 3x/3 :
Lemma. For positive d,x, we have:
g(x,d)⩽{3x/3(8164)x/3−d,3x/3(98)d−x/3, if d⩽x/3; if d⩾x/3.
Proof. There are a few key observations needed, all of which are immediate from the definition:
- (x,d) is the maximum product of a sequence of d integers that sums to x.
- For any positive integer k, we have g(kx,kd)=g(x,d)k.
- If 2d⩽x⩽3d, then g(x,d)=23d−x3x−2d. Likewise, if 3d⩽x⩽4d then g(x,d)=34d−x4x−3d.
With these observations, if d⩽x/3, then
34(x−3d)g(3x,3d)⩽g(3x+12(x−3d),3d+4(x−3d))=g(15x−36d,4x−9d)
To calculate g(15x−36d,4x−9d), note that
3(4x−9d)=12x−27d⩽15x−36d,4(4x−9d)=16x−36d⩾15x−36d,
so
g(15x−36d,4x−9d)=34(4x−9d)−(15x−36d)4(15x−36d)−3(4x−9d)=3x43(x−3d)
Thus
g(x,d)3=g(3x,3d)=34(x−3d)34(x−3d)g(3x,3d)⩽34(x−3d)3x43(x−3d)=3x(8164)x−3d,
which completes the proof of the first claim. Likewise, if d⩾x/3,
32(3d−x)g(3x,3d)3⩽g(3x+6(3d−x),3d+2(3d−x))=g(18d−3x,9d−2x).
Again we have
2(9d−2x)⩽18−3x⩽18−3x+3(3d−x)=3(9d−2x),
so
g(18d−3x,9d−2x)=23(9d−2x)−(18d−3x)3(18d−3x)−2(9d−2x)=23(3d−x)3x.
Thus
g(x,d)3=g(3x,3d)=32(3d−x)23(3d−x)g(3x,3d)⩽32(3d−x)23(3d−x)3x=3x(98)3d−x
from which the second claim follows.