OFFSET
0,13
COMMENTS
In other words, subtract one from all nonzero digits in the factorial base representation (A007623) of n and shift it one step right (i.e., delete the rightmost zero), then convert back to decimal.
LINKS
Antti Karttunen, Table of n, a(n) for n = 0..10080
FORMULA
EXAMPLE
For 4, whose factorial base representation is "20" (as 4 = 2*2! + 0*1!), when we discard the rightmost zero, and subtract 1 from 2, we get "1", thus a(4) = 1.
For 18, whose factorial base representation is "300" (as 18 = 3*3! + 0*2! + 0*1!), when we discard the rightmost zero, and subtract 1 from 3, we get "20", thus a(18) = 4.
MATHEMATICA
nn = 95; m = 1; While[Factorial@ m < nn, m++]; m; Map[FromDigits[#, MixedRadix[Reverse@ Range[2, m]]] &[If[# == 0, 0, # - 1] & /@ Most@ IntegerDigits[#, MixedRadix[Reverse@ Range[2, m]]]] &, Range[0, nn]] (* Michael De Vlieger, Aug 11 2016, Version 10.2 *)
PROG
(Scheme) (define (A257684 n) (let loop ((n n) (z 0) (i 2) (f 0)) (cond ((zero? n) z) (else (let ((d (remainder n i))) (loop (quotient n i) (+ z (* f (- d (if (zero? d) 0 1)))) (+ 1 i) (if (zero? f) 1 (* f (- i 1)))))))))
(Python)
from sympy import factorial as f
def a007623(n, p=2):
return n if n<p else a007623(n//p, p+1)*10 + n%p
def a(n):
x=str(a007623(n))[:-1]
y="".join(str(int(i) - 1) if int(i)>0 else '0' for i in x)[::-1]
return 0 if n==1 else sum(int(y[i])*f(i + 1) for i in range(len(y)))
print([a(n) for n in range(101)]) # Indranil Ghosh, Jun 19 2017
CROSSREFS
KEYWORD
nonn,base
AUTHOR
Antti Karttunen, May 04 2015
STATUS
approved