login

Year-end appeal: Please make a donation to the OEIS Foundation to support ongoing development and maintenance of the OEIS. We are now in our 61st year, we have over 378,000 sequences, and we’ve reached 11,000 citations (which often say “discovered thanks to the OEIS”).

A338489
Let t be the closest triangular number to n! (in case n=2, the only case where we have a tie, take the larger t); then a(n) = n! - t.
2
0, 0, -1, 0, 3, 0, 17, -10, 134, 354, 1329, 4155, 3924, 19797, -94380, 787794, 2901480, -1907466, 38192984, 204434670, -304139881, 115819260, -12372023755, 6328965122, -397725674235, 1196412908415, 6734756394444, -6589458328753, 48604536424455, -1553224821563460, 2464230045322035
OFFSET
0,5
COMMENTS
It is conjectured that 0! = 1, 1! = 1, 3! = 6 and 5! = 120 are the only numbers that are both factorial (A000142) and triangular (A000217) numbers.
FORMULA
a(n) = n! - m*(m+1)/2 where m = floor(sqrt(2 * n!)).
a(n) = A000142(n) - A000217(A129960(n)).
EXAMPLE
a(7) = 7! - 100*101 / 2 = 5040 - 5050 = -10.
MATHEMATICA
ctn[n_]:=Module[{c=Floor[(Sqrt[1+8n!]-1)/2], tr1, tr2, trp}, tr1=(c(c+1))/2; tr2=((c+1)(c+2))/2; trp=Nearest[{tr1, tr2}, n!]; n!-trp]; Join[{0, 0, -1}, Flatten[Array[ctn, 30, 3]]] (* Harvey P. Dale, Aug 22 2021 *)
PROG
(PARI) a(n) = my(m = sqrtint(2*n!)); n! - m*(m+1)/2; \\ Michel Marcus, Nov 09 2020
(Python)
from math import factorial, isqrt
def A338489(n): return (f:=factorial(n))-((m:=isqrt(f<<1))*(m+1)>>1) # Chai Wah Wu, Aug 04 2022
CROSSREFS
KEYWORD
sign,easy
AUTHOR
Ruediger Jehn, Nov 09 2020
STATUS
approved

  NODES
orte 1
see 1
Story 1