cp's OEIS Frontend

This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.

A034968 Minimal number of factorials that add to n.

Original entry on oeis.org

0, 1, 1, 2, 2, 3, 1, 2, 2, 3, 3, 4, 2, 3, 3, 4, 4, 5, 3, 4, 4, 5, 5, 6, 1, 2, 2, 3, 3, 4, 2, 3, 3, 4, 4, 5, 3, 4, 4, 5, 5, 6, 4, 5, 5, 6, 6, 7, 2, 3, 3, 4, 4, 5, 3, 4, 4, 5, 5, 6, 4, 5, 5, 6, 6, 7, 5, 6, 6, 7, 7, 8, 3, 4, 4, 5, 5, 6, 4, 5, 5, 6, 6, 7, 5, 6, 6, 7, 7, 8, 6, 7, 7, 8, 8, 9, 4, 5, 5, 6, 6, 7, 5, 6, 6, 7
Offset: 0

Views

Author

Keywords

Comments

Equivalently, sum of digits when n is written in factorial base (A007623).
Equivalently, a(0)...a(n!-1) give the total number of inversions of the permutations of n elements in lexicographic order (the factorial numbers in rising base are the inversion tables of the permutations and their sum of digits give the total number of inversions, see example and the Fxtbook link). - Joerg Arndt, Jun 17 2011
Also minimum number of adjacent transpositions needed to produce each permutation in the list A055089, or number of swappings needed to bubble sort each such permutation. (See A055091 for the minimum number of any transpositions.)

Examples

			a(205) = a(1!*1 + 3!*2 + 4!*3 + 5!*1) = 1+2+3+1 = 7. [corrected by Shin-Fu Tsai, Mar 23 2021]
From _Joerg Arndt_, Jun 17 2011: (Start)
   n:    permutation   inv. table a(n)  cycles
   0:    [ 0 1 2 3 ]   [ 0 0 0 ]   0    (0) (1) (2) (3)
   1:    [ 0 1 3 2 ]   [ 0 0 1 ]   1    (0) (1) (2, 3)
   2:    [ 0 2 1 3 ]   [ 0 1 0 ]   1    (0) (1, 2) (3)
   3:    [ 0 2 3 1 ]   [ 0 1 1 ]   2    (0) (1, 2, 3)
   4:    [ 0 3 1 2 ]   [ 0 2 0 ]   2    (0) (1, 3, 2)
   5:    [ 0 3 2 1 ]   [ 0 2 1 ]   3    (0) (1, 3) (2)
   6:    [ 1 0 2 3 ]   [ 1 0 0 ]   1    (0, 1) (2) (3)
   7:    [ 1 0 3 2 ]   [ 1 0 1 ]   2    (0, 1) (2, 3)
   8:    [ 1 2 0 3 ]   [ 1 1 0 ]   2    (0, 1, 2) (3)
   9:    [ 1 2 3 0 ]   [ 1 1 1 ]   3    (0, 1, 2, 3)
  10:    [ 1 3 0 2 ]   [ 1 2 0 ]   3    (0, 1, 3, 2)
  11:    [ 1 3 2 0 ]   [ 1 2 1 ]   4    (0, 1, 3) (2)
  12:    [ 2 0 1 3 ]   [ 2 0 0 ]   2    (0, 2, 1) (3)
  13:    [ 2 0 3 1 ]   [ 2 0 1 ]   3    (0, 2, 3, 1)
  14:    [ 2 1 0 3 ]   [ 2 1 0 ]   3    (0, 2) (1) (3)
  15:    [ 2 1 3 0 ]   [ 2 1 1 ]   4    (0, 2, 3) (1)
  16:    [ 2 3 0 1 ]   [ 2 2 0 ]   4    (0, 2) (1, 3)
  17:    [ 2 3 1 0 ]   [ 2 2 1 ]   5    (0, 2, 1, 3)
  18:    [ 3 0 1 2 ]   [ 3 0 0 ]   3    (0, 3, 2, 1)
  19:    [ 3 0 2 1 ]   [ 3 0 1 ]   4    (0, 3, 1) (2)
  20:    [ 3 1 0 2 ]   [ 3 1 0 ]   4    (0, 3, 2) (1)
  21:    [ 3 1 2 0 ]   [ 3 1 1 ]   5    (0, 3) (1) (2)
  22:    [ 3 2 0 1 ]   [ 3 2 0 ]   5    (0, 3, 1, 2)
  23:    [ 3 2 1 0 ]   [ 3 2 1 ]   6    (0, 3) (1, 2)
(End)
		

Crossrefs

Cf. A368342 (partial sums), A001809 (sums of n! terms).
Cf. A227148 (positions of even terms), A227149 (of odd terms).
Differs from analogous A276150 for the first time at n=24.
Positions of records are A200748.

Programs

  • Maple
    [seq(convert(fac_base(j),`+`),j=0..119)]; # fac_base and PermRevLexUnrank given in A055089. Perm2InversionVector in A064039
    Or alternatively: [seq(convert(Perm2InversionVector(PermRevLexUnrank(j)),`+`),j=0..119)];
    # third Maple program:
    b:= proc(n, i) local q;
          `if`(n=0, 0, b(irem(n, i!, 'q'), i-1)+q)
        end:
    a:= proc(n) local k;
          for k while k!Alois P. Heinz, Nov 15 2012
  • Mathematica
    a[n_] := Module[{s=0, i=2, k=n}, While[k > 0, k = Floor[n/i!]; s = s + (i-1)*k; i++]; n-s]; Table[a[n], {n, 0, 105}] (* Jean-François Alcover, Nov 06 2013, after Benoit Cloitre *)
  • PARI
    a(n)=local(k,r);k=2;r=0;while(n>0,r+=n%k;n\=k;k++);r \\ Franklin T. Adams-Watters, May 13 2009
    
  • Python
    def a(n):
        k=2
        r=0
        while n>0:
            r+=n%k
            n=n//k
            k+=1
        return r
    print([a(n) for n in range(201)]) # Indranil Ghosh, Jun 19 2017, after PARI program
    
  • Python
    def A034968(n, p=2): return n if n
  • Scheme
    (define (A034968 n) (let loop ((n n) (i 2) (s 0)) (cond ((zero? n) s) (else (loop (quotient n i) (+ 1 i) (+ s (remainder n i)))))))
    ;; Antti Karttunen, Aug 29 2016
    

Formula

a(n) = n - Sum_{i>=2} (i-1)*floor(n/i!). - Benoit Cloitre, Aug 26 2003
G.f.: 1/(1-x)*Sum_{k>0} (Sum_{i=1..k} i*x^(i*k!))/(Sum_{i=0..k} x^(i*k!)). - Franklin T. Adams-Watters, May 13 2009
From Antti Karttunen, Aug 29 2016: (Start)
a(0) = 0; for n >= 1, a(n) = A099563(n) + a(A257687(n)).
a(0) = 0; for n >= 1, a(n) = A060130(n) + a(A257684(n)).
Other identities. For all n >= 0:
a(n) = A001222(A276076(n)).
a(n) = A276146(A225901(n)).
a(A000142(n)) = 1, a(A007489(n)) = n, a(A033312(n+1)) = A000217(n).
a(A056019(n)) = a(n).
A219651(n) = n - a(n).
(End)

Extensions

Additional comments from Antti Karttunen, Aug 23 2001