Let Tn be the number we are looking for, then Tn+1 is the corresponding number for the set S∪{n+1}. Consider Γn+1−Tn, it represents the number of triangles with one side length n+1 and the other two sides being different numbers from S. For each such triangle, the sum of the lengths of the two sides not equal to n+1 is one of the following numbers:
2n−1,2n−2,⋯,n+3,n+2
(there are n−2 such numbers).
The number of triangles with these sums are respectively
1,1,2,2,3,3,⋯, up to n−2 terms (∵2n−i=n+(n−i)=(n−1)+(n−i+1)=(n−2)+(n−i+2)=⋯), so, Tn+1−Tn=1+1+2+2+3+3+⋯ (up to n−2 terms), ={41n(n−2),41(n−1)2. ( n is even )(n is odd)
Thus, T2τ−T2r−2
=(T2r−T2r−1)+(T2r−1⋯T2r)=(r⋯1)2+(r−1)(r−2)=2r2−5r+3.
Substituting r with r−1,r−2,⋯,4,3 in (1) and adding all the resulting equations, we get
T2τ−T4=2⋅61r(r+1)(2r+1)−5⋅r(r+1)+3r−(2×22−5×2+1)=61r(r−1)(4r−5)−1.
Clearly, T4=1 (only 2, 3 form a triangle, 1 cannot form a triangle with any two of 2, 3, 4). Therefore,
T2r=61r(r−1)(4r−5).
From this, T2r+1=T2r+r(r−1)
=61r(r−1)(4r+1),
i.e., TD=(241n(n−2)(2n−5),(n=2r)241(n−1)(n−3)(2n−1),
(n=2r+1).