OFFSET
0,3
COMMENTS
The a(n)-th triangular number is the smallest triangular number that is greater than or equal to half of the n-th triangular number.
LINKS
Matthew Scroggs, Table of n, a(n) for n = 0..10000
FORMULA
a(n) = ceiling((sqrt(2n^2 + 2n + 1) - 1)/2). - Charles R Greathouse IV, Apr 17 2015
EXAMPLE
For n=4, the 4th triangular number is 10. a(4)=3 as the 3rd triangular number is the first which is 5 or more.
MATHEMATICA
f[n_] := Block[{t = Accumulate[Range@ n], k, m}, {1}~Join~Rest@ Flatten@ Reap@ For[k = 1, k < n, m = 1; While[t[[m]] < t[[k]]/2, m++]; Sow[m], k++]]; f@ 80 (* Michael De Vlieger, Apr 17 2015 *)
PROG
(Python)
def tri(n):
return .5*n*(n+1)
for n in range(1, 10001):
k = 1
while 2*tri(k)<tri(n):
k+=1
print(k)
(PARI) a(n) = my(t = n*(n+1)/4, k = 0); while(k*(k+1)/2 < t, k++); k; \\ Michel Marcus, Apr 17 2015
(Magma) [Ceiling((Sqrt(2*n^2 + 2*n + 1) - 1)/2): n in [1..80]]; // Vincenzo Librandi, Apr 18 2015
(MIT/GNU Scheme) (define (A257175 n) (ceiling->exact (/ (+ -1 (sqrt (+ (* 2 n n) n n 1))) 2))) ;; After Greathouse's formula - Antti Karttunen, Apr 18 2015
CROSSREFS
KEYWORD
nonn,easy,changed
AUTHOR
Matthew Scroggs, Apr 17 2015
STATUS
approved