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.
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)
[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
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 *)
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
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
def A034968(n, p=2): return n if nA034968(n//p, p+1) + n%p print([A034968(n) for n in range(106)]) # Michael S. Branicky, Oct 27 2024
(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
a(1000) = a(1*6! + 2*5! + 1*4! + 2*3! + 2*2!) = (7-1)*6! + (6-2)*5! + (5-1)*4! + (4-2)*3! + (3-2)*2! = 4910. a(1397) = a(1*6! + 5*5! + 3*4! + 0*3! + 2*2! + 1*1!) = (7-1)*6! + (6-5)*5! + (5-3)*4! + (3-2)*2! + (2-1)*1! = 4491.
b = MixedRadix[Reverse@ Range[2, 12]]; Table[FromDigits[Map[Boole[# > 0] &, #] (Reverse@ Range[2, Length@ # + 1] - #), b] &@ IntegerDigits[n, b], {n, 0, 82}] (* Version 10.2, or *) f[n_] := Block[{a = {{0, n}}}, Do[AppendTo[a, {First@ #, Last@ #} &@ QuotientRemainder[a[[-1, -1]], Times @@ Range[# - i]]], {i, 0, #}] &@ NestWhile[# + 1 &, 0, Times @@ Range[# + 1] <= n &]; Most@ Rest[a][[All, 1]] /. {} -> {0}]; g[w_List] := Total[Times @@@ Transpose@ {Map[Times @@ # &, Range@ Range[0, Length@ w]], Reverse@ Append[w, 0]}]; Table[g[Map[Boole[# > 0] &, #] (Reverse@ Range[2, Length@ # + 1] - #)] &@ f@ n, {n, 0, 82}] (* Michael De Vlieger, Aug 29 2016 *)
a(n)=my(s=0,d,k=2);while(n,d=n%k;n=n\k;if(d,s=s+(k-d)*(k-1)!);k=k+1);return(s)
from sympy import factorial as f def a(n): s=0 k=2 while(n): d=n%k n=(n//k) if d: s=s+(k - d)*f(k - 1) k+=1 return s print([a(n) for n in range(101)]) # Indranil Ghosh, Jun 19 2017
(define (A225901 n) (let loop ((n n) (z 0) (m 2) (f 1)) (cond ((zero? n) z) (else (loop (quotient n m) (if (zero? (modulo n m)) z (+ z (* f (- m (modulo n m))))) (+ 1 m) (* f m)))))) ;; One implementing the first recurrence, with memoization-macro definec: (definec (A225901 n) (if (zero? n) n (+ (A276091 (A275736 n)) (A153880 (A225901 (A257684 n)))))) ;; Antti Karttunen, Aug 29 2016
128 is in the sequence since 5! + 3! + 2! = 128. a(22) = 128. a(22) = a(6) + (1 + floor(log(16) / log(2)))! = 8 + 5! = 128. Also, 22 = 10110_2. Therefore, a(22) = 1 * 5! + 0 * 4! + 1 * 3! + 1 + 2! + 0 * 0! = 128. - _David A. Corneth_, Aug 21 2016
import Data.List (elemIndices) a059590 n = a059590_list !! n a059590_list = elemIndices 1 $ map a115944 [0..] -- Reinhard Zumkeller, Dec 04 2011
[seq(bin2facbase(j),j=0..64)]; bin2facbase := proc(n) local i; add((floor(n/(2^i)) mod 2)*((i+1)!),i=0..floor_log_2(n)); end; floor_log_2 := proc(n) local nn,i; nn := n; for i from -1 to n do if(0 = nn) then RETURN(i); fi; nn := floor(nn/2); od; end; # next Maple program: a:= n-> (l-> add(l[j]*j!, j=1..nops(l)))(Bits[Split](n)): seq(a(n), n=0..57); # Alois P. Heinz, Aug 12 2025
a[n_] := Reverse[id = IntegerDigits[n, 2]].Range[Length[id]]!; Table[a[n], {n, 0, 60}] (* Jean-François Alcover, Jun 19 2012, after Philippe Deléham *)
a(n) = if(n>0, a(n-msb(n)) + (1+logint(n,2))!, 0) msb(n) = 2^#binary(n)>>1 {my(b = binary(n)); sum(i=1,#b,b[i]*(#b+1-i)!)} \\ David A. Corneth, Aug 21 2016
def facbase(k, f): return sum(f[i] for i, bi in enumerate(bin(k)[2:][::-1]) if bi == "1") def auptoN(N): # terms up to N factorial-base digits; 13 generates b-file f = [factorial(i) for i in range(1, N+1)] return list(facbase(k, f) for k in range(2**N)) print(auptoN(5)) # Michael S. Branicky, Oct 15 2022
19 = 3*(3!) + 0*(2!) + 1*(1!), thus it is written as "301" in factorial base (A007623). The count of nonzero digits in that representation is 2, so a(19) = 2.
A060130(n) = count_nonfixed(convert(PermUnrank3R(n), 'disjcyc'))-nops(convert(PermUnrank3R(n), 'disjcyc')) or nops(fac_base(n))-nops(positions(0, fac_base(n))) fac_base := n -> fac_base_aux(n, 2); fac_base_aux := proc(n, i) if(0 = n) then RETURN([]); else RETURN([op(fac_base_aux(floor(n/i), i+1)), (n mod i)]); fi; end; count_nonfixed := l -> convert(map(nops, l), `+`); positions := proc(e, ll) local a, k, l, m; l := ll; m := 1; a := []; while(member(e, l[m..nops(l)], 'k')) do a := [op(a), (k+m-1)]; m := k+m; od; RETURN(a); end; # For procedure PermUnrank3R see A060117
Block[{nn = 105, r}, r = MixedRadix[Reverse@ Range[2, -1 + SelectFirst[Range@ 12, #! > nn &]]]; Array[Count[IntegerDigits[#, r], k_ /; k > 0] &, nn, 0]] (* Michael De Vlieger, Dec 30 2017 *)
(define (A060130 n) (let loop ((n n) (i 2) (s 0)) (cond ((zero? n) s) (else (loop (quotient n i) (+ 1 i) (+ s (if (zero? (remainder n i)) 0 1))))))) ;; Two other implementations, that use memoization-macro definec: (definec (A060130 n) (if (zero? n) n (+ 1 (A060130 (A257687 n))))) (definec (A060130 n) (if (zero? n) n (+ (A257511 n) (A060130 (A257684 n))))) ;; Antti Karttunen, Dec 30 2017
r = MixedRadix[Reverse@ Range[2, 12]]; Select[Range@ 105, Total@ Boole@ Map[SameQ @@ # &, Transpose@{#, Range@ Length@ #}] > 0 &@ Reverse@ IntegerDigits[#, r] &] (* Michael De Vlieger, Aug 14 2016, Version 10.2 *)
from sympy import factorial as f def a007623(n, p=2): return n if n0 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))]) def a260736(n): return 0 if n==0 else n%2 + a260736(a257684(n)) print([n for n in range(106) if a260736(n)>0]) # Indranil Ghosh, Jun 20 2017
For n=15, f(15,2) = floor(15/2)=7, f(7,3)=2, f(2,4)=0, so a(15)=2. From _Antti Karttunen_, Dec 24 2015: (Start) Example illustrating the role of this sequence in factorial base representation: n A007623(n) a(n) [= the most significant digit]. 0 = 0 0 1 = 1 1 2 = 10 1 3 = 11 1 4 = 20 2 5 = 21 2 6 = 100 1 7 = 101 1 8 = 110 1 9 = 111 1 10 = 120 1 11 = 121 1 12 = 200 2 13 = 201 2 14 = 210 2 15 = 211 2 16 = 220 2 17 = 221 2 18 = 300 3 etc. Note that there is no any upper bound for the size of digits in this representation. (End)
Table[Floor[n/#] &@ (k = 1; While[(k + 1)! <= n, k++]; k!), {n, 0, 120}] (* Michael De Vlieger, Aug 30 2016 *)
A099563(n) = { my(i=2,dig=0); until(0==n, dig = n % i; n = (n - dig)/i; i++); return(dig); }; \\ Antti Karttunen, Dec 24 2015
def a(n): i=2 d=0 while n: d=n%i n=(n - d)//i i+=1 return d print([a(n) for n in range(201)]) # Indranil Ghosh, Jun 21 2017, after PARI code
(define (A099563 n) (let loop ((n n) (i 2)) (let* ((dig (modulo n i)) (next-n (/ (- n dig) i))) (if (zero? next-n) dig (loop next-n (+ 1 i)))))) (definec (A099563 n) (cond ((zero? n) n) ((= 1 (A265333 n)) 1) (else (+ 1 (A099563 (A257684 n)))))) ;; Based on given recurrence, using the memoization-macro definec ;; Antti Karttunen, Dec 24-25 2015
Factorial base representation (A007623) of 1 is "1", discarding the most significant digit leaves nothing, taken to be zero, thus a(1) = 0. Factorial base representation of 2 is "10", discarding the most significant digit leaves "0", thus a(2) = 0. Factorial base representation of 3 is "11", discarding the most significant digit leaves "1", thus a(3) = 1. Factorial base representation of 4 is "20", discarding the most significant digit leaves "0", thus a(4) = 0.
f[n_] := Block[{m = p = 1}, While[p*(m + 1) <= n, p = p*m; m++]; Mod[n, p]]; Array[f, 101, 0] (* Robert G. Wilson v, Jul 21 2015 *)
from sympy import factorial as f def a007623(n, p=2): return n if n
(define (A257687 n) (- n (A257686 n)))
Factorial base representation (A007623) of 4 is "20", the smallest digit which is not zero is "2", thus a(4) = 2.
a[n_] := Module[{k = n, m = 2, rmin = n, r}, While[{k, r} = QuotientRemainder[k, m]; k != 0 || r != 0, If[0 < r < rmin, rmin = r]; m++]; rmin]; Array[a, 100, 0] (* Amiram Eldar, Jan 23 2024 *)
def A(n, p=2): return n if n
(define (A257679 n) (let loop ((n n) (i 2) (mind 0)) (if (zero? n) mind (let ((d (modulo n i))) (loop (/ (- n d) i) (+ 1 i) (cond ((zero? mind) d) ((zero? d) mind) (else (min d mind)))))))) ;; Alternative implementations based on given recurrences, using memoizing definec-macro: (definec (A257679 n) (if (zero? (A257687 n)) (A099563 n) (min (A099563 n) (A257679 (A257687 n))))) (definec (A257679 n) (cond ((zero? n) n) ((= 1 (A257680 n)) 1) (else (+ 1 (A257679 (A257684 n))))))
n A007623(n) [subtract 1 from max.digits a(n) [in factorial then shift one digit right] [reinterpret base] in decimal] 0 0 -> 0 = 0 1 1 -> 0 = 0 2 10 -> 1 = 1 3 11 -> 1 = 1 4 20 -> 1 = 1 5 21 -> 1 = 1 6 100 -> 10 = 2 7 101 -> 10 = 2 8 110 -> 11 = 3 9 111 -> 11 = 3 10 120 -> 11 = 3 11 121 -> 11 = 3 12 200 -> 20 = 4 13 201 -> 20 = 4 14 210 -> 21 = 5 15 211 -> 21 = 5 16 220 -> 21 = 5 17 221 -> 21 = 5 18 300 -> 20 = 4 ... 23 321 -> 21 = 5 119 4321 -> 321 = 23
from sympy import factorial as f def a007623(n, p=2): return n if n
Comments