OFFSET
2,1
COMMENTS
The number of ways n can be written as difference of two triangular numbers is sequence A136107
Note that n = t(k)-t(j) implies 2n = (k-j)(k+j+1), where (k-j) and (k+j+1) are of opposite parity. Let d be the odd element of { k-j, k+j+1 }. Then d is an odd divisor of n and k = ( d + 2n/d - 1 ) / 2. Therefore a(n) = ( min{ d + 2n/d } - 1 ) / 2 where d runs through all odd divisors of n, except perhaps (sqrt(8*n+1) +- 1)/2 which correspond to j=0. See PARI program. The restriction that j > 0 seems artificial. If it is removed we get A212652. - Max Alekseyev, Mar 31 2008
LINKS
Vincenzo Librandi, Table of n, a(n) for n = 2..1000
Peter Pein, Mathematica notebook containing a faster algorithm.
EXAMPLE
a(30)=8, because 30 = T(30) - T(29) = T(11) - T(8) = T(9) - T(5) = T(8) - T(3) and 8 is the least index of the minuends.
MATHEMATICA
T=#(#+1)/2&; Min[k/.{ToRules[Reduce[{T[k]-T[j]\[Equal]#, 0<j<k}, {j, k}, Integers]]}]&/@Range[2, 100]
PROG
(PARI) { a(n) = local(m); m=2*n+1; fordiv(n/2^valuation(n, 2), d, if((2*d+1)^2!=8*n+1&&(2*d-1)^2!=8*n+1, m=min(m, d+(2*n)\d))); (m-1)\2 }
vector(100, n, a(n)) \\ Max Alekseyev, Mar 31 2008
CROSSREFS
KEYWORD
nonn
AUTHOR
Peter Pein (petsie(AT)dordos.net), Mar 30 2008
STATUS
approved