[go: up one dir, main page]

login
Search: a136695 -id:a136695
     Sort: relevance | references | number | modified | created      Format: long | short | data
a(n) is the final nonzero digit of n!.
+10
32
1, 1, 2, 6, 4, 2, 2, 4, 2, 8, 8, 8, 6, 8, 2, 8, 8, 6, 8, 2, 4, 4, 8, 4, 6, 4, 4, 8, 4, 6, 8, 8, 6, 8, 2, 2, 2, 4, 2, 8, 2, 2, 4, 2, 8, 6, 6, 2, 6, 4, 2, 2, 4, 2, 8, 4, 4, 8, 4, 6, 6, 6, 2, 6, 4, 6, 6, 2, 6, 4, 8, 8, 6, 8, 2, 4, 4, 8, 4, 6, 8, 8, 6, 8, 2, 2, 2, 4, 2, 8, 2, 2, 4, 2, 8, 6, 6, 2, 6
OFFSET
0,3
COMMENTS
This sequence is not ultimately periodic. This can be deduced from the fact that the sequence can be obtained as a fixed point of a morphism. - Jean-Paul Allouche, Jul 25 2001
The decimal number 0.1126422428... formed from these digits is a transcendental number; see the article by G. Dresden. The Mathematica code uses Dresden's formula for the last nonzero digit of n!; this is more efficient than simply calculating n! and then taking its least-significant digit. - Greg Dresden, Feb 21 2006
From Robert G. Wilson v, Feb 16 2011: (Start)
(mod 10) == 2 4 6 8
10^
1 4 2 1 1
2 28 23 22 25
3 248 247 260 243
4 2509 2486 2494 2509
5 25026 24999 24972 25001
6 249993 250012 250040 249953
7 2500003 2499972 2499945 2500078
8 25000078 24999872 25000045 25000003
9 249999807 250000018 250000466 249999707 (End)
REFERENCES
J.-P. Allouche and J. Shallit, Automatic Sequences, Cambridge Univ. Press, 2003, p. 202.
Gardner, M. "Factorial Oddities." Ch. 4 in Mathematical Magic Show: More Puzzles, Games, Diversions, Illusions and Other Mathematical Sleight-of-Mind from Scientific American. New York: Vintage, pp. 50-65, 1978
S. Kakutani, Ergodic theory of shift transformations, in Proc. 5th Berkeley Symp. Math. Stat. Prob., Univ. Calif. Press, vol. II, 1967, 405-414.
Popular Computing (Calabasas, CA), Problem 120, Factorials, Vol. 4 (No. 36, Mar 1976), page PC36-3.
LINKS
F. M. Dekking, Regularity and irregularity of sequences generated by automata Sém. Théor. Nombres, Bordeaux, Exposé 9, 1979-1980, pages 9-01 to 9-10.
Jean-Marc Deshouillers, A footnote to the least non zero digit of n! in base 12, Uniform Distribution Theory 7:1 (2012), pp. 71-73.
Jean-Marc Deshouillers, Yet Another Footnote to the Least Non Zero Digit of n! in Base 12. Unif. Distrib. Theory 11 (2016), no. 2, 163-167.
Gregory P. Dresden, Three transcendental numbers from the last non-zero digits of n^n, F_n and n!, Mathematics Magazine, pp. 96-105, vol. 81, 2008.
Gregory P. Dresden, Two Irrational Numbers from the Last Nonzero Digits of n! and n^n, Mathematics Magazine, Vol. 74, No. 4 (2001), 316-320.
Gregory P. Dresden, Research Papers.
Fritz Jacob (fritzjacob(AT)gmail.com), A way to compute a(n)
J. C. Martin, The structure of generalized Morse minimal sets on m symbols, Trans. Amer. Math. Soc. 232 (1977), 343-355.
T. Sillke, What are the next entries for the following sequences? Puzzle U asks for the next number after 2642242888682886824484644846.
Eric Weisstein's World of Mathematics, Factorial
FORMULA
The generating function for n>1 is as follows: for n = a_0 + 5*a_1 + 5^2*a_2 + ... + 5^N*a_N (the expansion of n in base-5), then the last nonzero digit of n!, for n>1, is 6*Product_{i=0..N} (a_i)! (2^(i a_i)) mod 10. - Greg Dresden, Feb 21 2006
a(n) = f(n,1,0) with f(n,x,e) = if n < 2 then A010879(x*A000079(e)) else f(n-1,A010879(x*A132740(n),e+A007814(n)-A112765(n)). - Reinhard Zumkeller, Aug 16 2008
From Washington Bomfim, Jan 09 2011: (Start)
a(0) = 1, a(1) = 1, if n >= 2, with
n represented in base 5 as (a_h, ..., a_1, a_0)_5,
t = Sum_{i = h, h-1, ... , 0} (a_i even),
x = Sum_{i=h, h-1, ... , 1} (Sum_{k=h, h-1, ..., i}(a_i)),
z = (x + t/2) mod 4, and y = 2^z,
a(n) = 6*(y mod 2) + y*(1-(y mod 2)).
For n >= 5, and n mod 5 = 0,
i) a(n) = a(n+1) = a(n+3),
ii) a(n+2) = 2*a(n) mod 10, and
iii) a(n+4) = 4*a(n) mod 10.
For k not equal to 1, a(10^k) = a(2^k). See second Dresden link, and second Bomfim link.
(End)
EXAMPLE
6! = 720, so a(6) = 2.
MATHEMATICA
f[n_]:=Module[{m=n!}, While[Mod[m, 10]==0, m=m/10]; Mod[m, 10]]
Table[f[i], {i, 0, 100}]
f[n_] := Mod[6Times @@ (Rest[FoldList[{ 1 + #1[[1]], #2!2^(#1[[1]]#2)} &, {0, 0}, Reverse[IntegerDigits[n, 5]]]]), 10][[2]]; Join[{1, 1}, Table[f[n], {n, 2, 100}]] (* program contributed by Jacob A. Siehler, Greg Dresden, Feb 21 2006 *)
zOF[n_Integer?Positive] := Module[{maxpow=0}, While[5^maxpow<=n, maxpow++]; Plus@@Table[Quotient[n, 5^i], {i, maxpow-1}]]; Flatten[Table[ Take[ IntegerDigits[ n!], {-zOF[n]-1}], {n, 100}]] (* Harvey P. Dale, Dec 16 2010 *)
f[n_]:=Block[{id=IntegerDigits[n!, 10]}, While[id[[-1]]==0, id=Most@id]; id[[-1]]]; Table[f@n, {n, 0, 100}] (* Vincenzo Librandi, Sep 07 2017 *)
PROG
(Python)
def a(n):
if n <= 1: return 1
return 6*[1, 1, 2, 6, 4, 4, 4, 8, 4, 6][n%10]*3**(n/5%4)*a(n/5)%10
(Python)
from functools import reduce
from sympy.ntheory.factor_ import digits
def A008904(n): return reduce(lambda x, y:x*y%10, (((6, 2, 4, 8, 6, 2, 4, 8, 2, 4, 8, 6, 6, 2, 4, 8, 4, 8, 6, 2)[(a<<2)|(i*a&3)] if i*a else (1, 1, 2, 6, 4)[a]) for i, a in enumerate(digits(n, 5)[-1:0:-1])), 6) if n>1 else 1 # Chai Wah Wu, Dec 07 2023
(PARI) a(n) = r=1; while(n>0, r *= Mod(4, 10)^((n\10)%2) * [1, 2, 6, 4, 2, 2, 4, 2, 8][max(n%10, 1)]; n\=5); lift(r) \\ Charles R Greathouse IV, Nov 05 2010; cleaned up by Max Alekseyev, Jan 28 2012
(Sage)
def A008904(n):
# algorithm from David Wilson, http://oeis.org/A008904/a008904b.txt
if n == 0 or n == 1: return 1
dd = n.digits(base=5)
x = sum(i*d for i, d in enumerate(dd))
y = sum(d for d in dd if d % 2 == 0)/2
z = 2**((x+y) % 4)
if z == 1: z = 6
return z # D. S. McNeil, Dec 09 2010
(Haskell)
a008904 n = a008904_list !! n
a008904_list = 1 : 1 : f 2 1 where
f n x = x' `mod` 10 : f (n+1) x' where
x' = g (n * x) where
g m | m `mod` 5 > 0 = m
| otherwise = g (m `div` 10)
-- Reinhard Zumkeller, Apr 08 2011
KEYWORD
nonn,base,nice
AUTHOR
EXTENSIONS
More terms from Greg Dresden, Feb 21 2006
STATUS
approved
Final nonzero digit of n! in base 3.
+10
16
1, 1, 2, 2, 2, 1, 2, 2, 1, 1, 1, 2, 2, 2, 1, 2, 2, 1, 2, 2, 1, 1, 1, 2, 1, 1, 2, 2, 2, 1, 1, 1, 2, 1, 1, 2, 2, 2, 1, 1, 1, 2, 1, 1, 2, 1, 1, 2, 2, 2, 1, 2, 2, 1, 2, 2, 1, 1, 1, 2, 1, 1, 2, 2, 2, 1, 1, 1, 2, 1, 1, 2, 1, 1, 2, 2, 2, 1, 2, 2, 1, 1, 1, 2, 2, 2, 1, 2, 2, 1, 1, 1, 2, 2, 2, 1, 2, 2, 1, 2, 2, 1, 1, 1, 2
OFFSET
0,3
FORMULA
From David Radcliffe, Sep 03 2021: (Start)
a(n) = (n! / A060828(n)) mod 3;
a(n) = 1 + (A189672(n) mod 2);
a(6*n) = a(6*n+1) = a(2*n);
a(6*n+2) = 3 - a(2*n);
a(6*n+3) = a(6*n+4) = 3 - a(2*n+1);
a(6*n+5) = a(2*n+1).
(End)
a(n) = A008904(A127110(n)). - Michel Marcus, Sep 04 2021
From Kevin Ryde, Dec 03 2022: (Start)
a(n) = 1 if n written in base 9 has an even number of digits {2,3,4,6,7}; and otherwise a(n) = 2.
Fixed point of the morphism 1 -> 1,1,2,2,2,1,2,2,1; 2 -> 2,2,1,1,1,2,1,1,2; starting from 1.
(End)
a(n) = A212307(n) mod 3. - Ridouane Oudra, Sep 25 2024
EXAMPLE
6! = 720 decimal = 222200 ternary, so a(6) = 2.
MATHEMATICA
f[n_] := Mod[6 Times @@ (Rest[ FoldList[{1 + #1[[1]], #2! 2^(#1[[1]] #2)} &, {0, 0}, Reverse[ IntegerDigits[n, 3]]]]), 10][[2]]; # /. {0 -> 1} & /@ Mod[Table[f@n, {n, 0, 104}], 3] (* Robert G. Wilson v, Apr 17 2010 *)
fnzd[n_]:=Module[{sidn3=Split[IntegerDigits[n!, 3]]}, If[MemberQ[ Last[ sidn3], 0], sidn3[[-2, 1]], sidn3[[-1, 1]]]]; Array[fnzd, 110, 0] (* Harvey P. Dale, May 03 2018 *)
PROG
(PARI) a(n) = vecsum([bittest(220, b) |b<-digits(n, 9)])%2 + 1; \\ Kevin Ryde, Dec 03 2022
KEYWORD
base,easy,nonn
AUTHOR
Carl R. White, Jan 16 2008
EXTENSIONS
More terms from Robert G. Wilson v, Apr 17 2010
STATUS
approved
Final nonzero digit of n! in base 4.
+10
16
1, 1, 2, 2, 2, 2, 1, 3, 2, 2, 3, 1, 3, 3, 2, 2, 2, 2, 3, 1, 1, 1, 2, 2, 3, 3, 2, 2, 2, 2, 1, 3, 2, 2, 3, 1, 1, 1, 2, 2, 1, 1, 2, 2, 2, 2, 3, 1, 3, 3, 2, 2, 2, 2, 3, 1, 2, 2, 3, 1, 3, 3, 2, 2, 2, 2, 3, 1, 1, 1, 2, 2, 1, 1, 2, 2, 2, 2, 3, 1, 1, 1, 2, 2, 2, 2, 1, 3, 2, 2, 1, 3, 1, 1, 2, 2, 3, 3, 2, 2
OFFSET
0,3
LINKS
EXAMPLE
6! = 720 decimal = 23100 quartal, so a(6) = 1.
MATHEMATICA
nzd[n_]:=Module[{rd=RealDigits[n!, 4][[1]]}, If[Last[rd]!=0, Last[rd], Last[ Flatten[Most[Split[rd]]]]]]; Array[nzd, 100, 0] (* Harvey P. Dale, May 08 2014 *)
KEYWORD
base,easy,nonn
AUTHOR
Carl R. White, Jan 16 2008
STATUS
approved
Final nonzero digit of n! in base 12.
+10
16
1, 1, 2, 6, 2, 10, 5, 11, 4, 6, 7, 5, 5, 5, 10, 6, 8, 4, 11, 5, 4, 7, 10, 2, 4, 4, 8, 6, 6, 6, 3, 9, 8, 10, 4, 8, 11, 11, 10, 6, 4, 8, 10, 10, 8, 6, 1, 11, 8, 8, 4, 2, 8, 4, 9, 3, 10, 6, 1, 11, 7, 7, 2, 6, 8, 4, 4, 4, 8, 4, 4, 8, 4, 4, 8, 2, 8, 4, 8, 8, 4, 3, 6, 6, 6, 6, 7, 9, 2, 10, 3, 9, 5, 9, 6, 6, 8, 8, 4
OFFSET
0,3
COMMENTS
The asymptotic densities of the numbers k such that a(k) = m is 1/2 for m = 4 or 8, and 0 otherwise (Deshouillers and Ruzsa, 2011). Therefore, the asymptotic mean of this sequence is 6. There are infinitely many numbers k such that a(k) = m for each of the values m = 3, 6, or 9 (Deshouillers, 2012). - Amiram Eldar, Jan 11 2021
LINKS
Michael De Vlieger, Table of n, a(n) for n = 0..10368 (10368 = 6 * 12^3)
Jean-Marc Deshouillers, A footnote to the least non zero digit of n! in base 12, Uniform Distribution Theory 7:1 (2012), pp. 71-73. [Wayback Machine link]
Jean-Marc Deshouillers, Yet Another Footnote to the Least Non Zero Digit of n! in Base 12. Unif. Distrib. Theory 11 (2016), no. 2, 163-167.
Jean-Marc Deshouillers and Imre Ruzsa, The least nonzero digit of n! in base 12, Publicationes Mathematicae, Vol. 79, No. 3-4 (2011), pp. 395-400.
Jean-Marc Deshouillers, Laurent Habsieger, Shanta Laishram, and Bernard Landreau, Sums of the digits in bases 2 and 3, arXiv:1611.08180 [math.NT], 2016. (See first page footnote.)
EXAMPLE
6! = 720 decimal = 500 duodecimal, so a(6) = 5.
MATHEMATICA
a136698[n_Integer] := Last[Select[IntegerDigits[n!, 12], # > 0 &]]; a136698 /@ Range[0, 144] (* Michael De Vlieger, Aug 13 2014 *)
KEYWORD
base,easy,nonn
AUTHOR
Carl R. White, Jan 16 2008
STATUS
approved
Final nonzero digit of n! in base 7.
+10
15
1, 1, 2, 6, 3, 1, 6, 6, 6, 5, 1, 4, 6, 1, 2, 2, 4, 5, 6, 2, 5, 1, 1, 2, 6, 3, 1, 6, 3, 3, 6, 4, 2, 3, 4, 6, 6, 5, 1, 4, 6, 1, 6, 6, 5, 1, 4, 6, 1, 1, 1, 2, 6, 3, 1, 6, 6, 6, 5, 1, 4, 6, 1, 2, 2, 4, 5, 6, 2, 5, 1, 1, 2, 6, 3, 1, 6, 3, 3, 6, 4, 2, 3, 4, 6, 6, 5, 1, 4, 6, 1, 6, 6, 5, 1, 4, 6, 1, 2, 2
OFFSET
0,3
EXAMPLE
6! = 720 decimal = 2046 septimal, so a(6) = 6.
KEYWORD
base,easy,nonn
AUTHOR
Carl R. White, Jan 16 2008
STATUS
approved
Final nonzero digit of n! in base 9.
+10
15
1, 1, 2, 6, 6, 3, 8, 2, 7, 7, 7, 5, 6, 6, 3, 2, 5, 4, 8, 8, 7, 3, 3, 6, 1, 7, 2, 6, 6, 3, 4, 7, 8, 3, 3, 6, 6, 6, 3, 7, 1, 5, 3, 3, 6, 3, 3, 6, 8, 5, 7, 6, 6, 3, 8, 8, 7, 3, 3, 6, 1, 7, 2, 5, 5, 1, 3, 3, 6, 4, 1, 8, 1, 1, 2, 6, 6, 3, 8, 2, 7, 7, 7, 5, 6, 6, 3, 2, 5, 4, 4, 4, 8, 6, 6, 3, 5, 8, 1, 2
OFFSET
0,3
EXAMPLE
6! = 720 decimal = 880 nonary, so a(6) = 8.
KEYWORD
base,easy,nonn
AUTHOR
Carl R. White, Jan 16 2008
STATUS
approved
Final nonzero digit of n! in base 11.
+10
15
1, 1, 2, 6, 2, 10, 5, 2, 5, 1, 10, 10, 10, 9, 5, 9, 1, 6, 9, 6, 10, 1, 2, 2, 4, 1, 4, 9, 10, 4, 10, 2, 9, 5, 5, 10, 8, 10, 6, 3, 10, 3, 5, 6, 2, 2, 4, 1, 4, 9, 10, 4, 10, 2, 9, 1, 1, 2, 6, 2, 10, 5, 2, 5, 1, 10, 5, 5, 10, 8, 10, 6, 3, 10, 3, 5, 6, 9, 9, 7, 10, 7, 2, 1, 7, 1, 9, 2, 5, 5, 10, 8, 10, 6, 3
OFFSET
0,3
EXAMPLE
6! = 720 decimal = 5A5 undecimal, so a(6) = 5.
KEYWORD
base,easy,nonn
AUTHOR
Carl R. White, Jan 16 2008
STATUS
approved
Final nonzero digit of n! in base 13.
+10
15
1, 1, 2, 6, 11, 3, 5, 9, 7, 11, 6, 1, 12, 12, 12, 11, 7, 2, 10, 8, 4, 6, 2, 7, 12, 1, 2, 2, 4, 12, 9, 6, 10, 5, 1, 9, 12, 2, 11, 7, 7, 1, 3, 12, 8, 9, 11, 10, 12, 3, 7, 6, 11, 11, 9, 1, 4, 7, 3, 8, 12, 4, 1, 11, 2, 10, 10, 7, 8, 6, 4, 11, 12, 5, 6, 8, 10, 3, 5, 5, 10, 4, 3, 2, 12, 6, 9, 3, 4, 5, 8, 4
OFFSET
0,3
EXAMPLE
6! = 720 decimal = 435 tridecimal, so a(6) = 5.
MATHEMATICA
f[s_List] := Block[{a = s[[ -1]], len = Length@s}, Append[s, If[Mod[len, 13] == 0, Mod[a*len/13, 13], Mod[a*len, 13]]]]; Nest[f, {1}, 100] (* Robert G. Wilson v, May 03 2009 *)
f[n_] := Block[{id = IntegerDigits[n!, 13]}, While[id[[ -1]] == 0, id = Most@id]; id[[ -1]]]; Table[ f@n, {n, 0, 100}] (* Robert G. Wilson v, May 03 2009 *)
KEYWORD
base,easy,nonn
AUTHOR
Carl R. White, Jan 16 2008
STATUS
approved
Final nonzero digit of n! in base 15.
+10
15
1, 1, 2, 6, 9, 8, 3, 6, 3, 12, 3, 3, 6, 3, 12, 12, 12, 9, 12, 3, 9, 9, 3, 9, 6, 9, 9, 3, 9, 6, 12, 12, 9, 12, 3, 12, 12, 9, 12, 3, 3, 3, 6, 3, 12, 6, 6, 12, 6, 9, 12, 12, 9, 12, 3, 6, 6, 12, 6, 9, 6, 6, 12, 6, 9, 9, 9, 3, 9, 6, 3, 3, 6, 3, 12, 9, 9, 3, 9, 6, 12, 12, 9, 12, 3, 12, 12, 9, 12, 3, 3, 3, 6
OFFSET
0,3
COMMENTS
From Robert Israel, Jun 08 2018: (Start)
For n >= 6, a(n) is 3, 6, 9 or 12.
For k >= 2, a(5*k) = a(5*k+1) = a(5*k+3). (End)
LINKS
EXAMPLE
6! = 720 decimal = 330 quindecimal, so a(6) = 3.
MAPLE
a:= 1: b:= 0: R[0]:= 1:
for n from 1 to 100 do
alpha:= padic:-ordp(n, 3);
beta:= padic:-ordp(n, 5);
a:= a * n/3^alpha/5^beta;
b:= b + alpha - beta;
R[n]:= a * 3 &^ b mod 15;
od:
seq(R[n], n=0..100); # Robert Israel, Jun 08 2018
MATHEMATICA
nzd[x_]:=If[x[[-1, 1]]==0, x[[-2, 1]], x[[-1, 1]]]; Table[nzd[Split[IntegerDigits[n!, 15]]], {n, 0, 100}] (* Harvey P. Dale, Jul 11 2023 *)
KEYWORD
base,easy,nonn
AUTHOR
Carl R. White, Jan 16 2008
STATUS
approved
Final nonzero digit of n! in base 16.
+10
15
1, 1, 2, 6, 8, 8, 13, 11, 8, 8, 15, 5, 12, 12, 8, 8, 8, 8, 3, 9, 4, 4, 8, 8, 12, 12, 8, 8, 14, 6, 4, 12, 8, 8, 11, 1, 4, 4, 8, 8, 4, 4, 8, 8, 2, 10, 12, 4, 12, 12, 8, 8, 2, 10, 12, 4, 14, 14, 12, 4, 7, 11, 10, 6, 8, 8, 11, 1, 4, 4, 8, 8, 4, 4, 8, 8, 10, 2, 12, 4, 4, 4, 8, 8, 6, 14, 4, 12, 2, 2, 4, 12
OFFSET
0,3
EXAMPLE
6! = 720 decimal = 2D0 hexadecimal, so a(6) = 13.
PROG
(PARI) a(n) = {d = digits(n!, 16); k = #d; while (!d[k] && (k!=1), k--); d[k]; } \\ Michel Marcus, Sep 21 2016
KEYWORD
base,easy,nonn
AUTHOR
Carl R. White, Jan 16 2008
STATUS
approved

Search completed in 0.013 seconds