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.

Showing 1-10 of 29 results. Next

A008904 a(n) is the final nonzero digit of n!.

Original entry on oeis.org

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

Views

Author

Keywords

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)

Examples

			6! = 720, so a(6) = 2.
		

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.

Crossrefs

Programs

  • 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
  • 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 *)
  • 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
    
  • 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
    # Maciej Ireneusz Wilczynski, Aug 23 2010
    
  • 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
    
  • 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
    

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)

Extensions

More terms from Greg Dresden, Feb 21 2006

A045520 Numbers k such that k! has initial digit '1'.

Original entry on oeis.org

0, 1, 5, 15, 19, 22, 25, 27, 35, 37, 42, 45, 48, 51, 55, 59, 63, 64, 69, 70, 76, 77, 78, 88, 89, 90, 91, 92, 93, 94, 95, 104, 105, 106, 107, 108, 109, 110, 111, 112, 123, 124, 125, 132, 133, 134, 140, 141, 146, 147, 152, 157, 158, 162, 167, 171, 175, 176, 179, 183
Offset: 1

Views

Author

Keywords

Comments

The asymptotic density of this sequence is log_10(2) = 0.301029... (A007524) (Kunoff, 1987). - Amiram Eldar, Jul 17 2020

Examples

			0 is a term since 0! = 1 has the initial digit 1.
		

Crossrefs

For factorials with initial digit d (1 <= d <= 9) see A045509, A045510, A045511, A045516, A045517, A045518, A282021, A045519; A045520, A045521, A045522, A045523, A045524, A045525, A045526, A045527, A045528, A045529. See also A000142, A007524, A008905.

Programs

  • Mathematica
    Select[ Range[ 0, 200 ], IntegerDigits[ #! ][ [ 1 ] ] == 1 & ]
  • PARI
    isok(n) = digits(n!)[1] == 1; \\ Michel Marcus, Feb 07 2017

Formula

A008905(a(n)) = 1. - Amiram Eldar, Jul 17 2020

A045521 Numbers k such that k! has initial digit '2'.

Original entry on oeis.org

2, 4, 16, 20, 23, 30, 32, 34, 39, 44, 47, 54, 58, 68, 75, 85, 86, 87, 113, 114, 115, 126, 135, 142, 148, 153, 159, 163, 168, 172, 180, 184, 188, 195, 205, 208, 211, 214, 217, 220, 223, 226, 234, 237, 242, 247, 252, 257, 262, 269, 276, 278, 287, 289, 302, 304
Offset: 1

Views

Author

Keywords

Comments

The asymptotic density of this sequence is log_10(3/2) = 0.176091... (see A154580) (Kunoff, 1987). - Amiram Eldar, Jul 17 2020

Examples

			4 is a term since 4! = 24 has the initial digit 2.
		

Crossrefs

For factorials with initial digit d (1 <= d <= 9) see A045509, A045510, A045511, A045516, A045517, A045518, A282021, A045519; A045520, A045521, A045522, A045523, A045524, A045525, A045526, A045527, A045528, A045529. See also A000142, A008905, A154580.

Programs

  • Mathematica
    Select[ Range[ 310 ], IntegerDigits[ #! ] [ [ 1 ] ] == 2 & ]
  • PARI
    isok(n) = digits(n!)[1] == 2; \\ Michel Marcus, Feb 07 2017

Formula

A008905(a(n)) = 2. - Amiram Eldar, Jul 17 2020

Extensions

Offset changed to 1 by Chai Wah Wu, Feb 07 2017

A045522 Numbers k such that k! has initial digit '3'.

Original entry on oeis.org

9, 10, 11, 17, 28, 36, 41, 50, 62, 67, 74, 83, 84, 116, 117, 127, 128, 136, 143, 149, 154, 164, 173, 177, 181, 192, 199, 202, 229, 245, 250, 255, 260, 267, 274, 283, 285, 296, 298, 300, 332, 334, 336, 349, 358, 360, 367, 374, 381, 386, 411, 416, 424, 435, 449
Offset: 1

Views

Author

Keywords

Comments

The asymptotic density of this sequence is log_10(4/3) = 0.124938... (Kunoff, 1987). - Amiram Eldar, Jul 17 2020

Examples

			9 is a term since 9! = 362880 has the initial digit 3.
		

Crossrefs

For factorials with initial digit d (1 <= d <= 9) see A045509, A045510, A045511, A045516, A045517, A045518, A282021, A045519; A045520, A045521, A045522, A045523, A045524, A045525, A045526, A045527, A045528, A045529. See also A000142, A008905.

Programs

  • Mathematica
    Select[ Range[ 500 ], IntegerDigits[ #! ] [ [ 1 ] ] == 3 & ]
  • PARI
    isok(n) = digits(n!)[1] == 3; \\ Michel Marcus, Feb 07 2017

Formula

A008905(a(n)) = 3. - Amiram Eldar, Jul 17 2020

A045523 Numbers k such that k! has initial digit '4'.

Original entry on oeis.org

8, 12, 26, 53, 57, 73, 82, 118, 129, 155, 160, 169, 185, 212, 215, 218, 232, 240, 265, 272, 281, 294, 338, 351, 369, 376, 388, 393, 398, 403, 408, 421, 432, 443, 446, 482, 485, 498, 515, 522, 533, 544, 548, 576, 580, 593, 602, 616, 621, 641, 646, 657, 668
Offset: 1

Views

Author

Keywords

Comments

The asymptotic density of this sequence is log_10(5/4) = 0.096910... (Kunoff, 1987). - Amiram Eldar, Jul 17 2020

Examples

			8 is a term since 8! = 40320 has the initial digit 4.
		

Crossrefs

For factorials with initial digit d (1 <= d <= 9) see A045509, A045510, A045511, A045516, A045517, A045518, A282021, A045519; A045520, A045521, A045522, A045523, A045524, A045525, A045526, A045527, A045528, A045529. See also A000142, A008905.

Programs

  • Mathematica
    Select[ Range[ 700 ], IntegerDigits[ #! ] [[ 1 ]] == 4 & ]
  • PARI
    isok(n) = digits(n!)[1] == 4; \\ Michel Marcus, Feb 07 2017

Formula

A008905(a(n)) = 4. - Amiram Eldar, Jul 17 2020

A045524 Numbers k such that k! has initial digit '5'.

Original entry on oeis.org

7, 21, 38, 46, 61, 66, 81, 119, 137, 144, 150, 165, 189, 196, 206, 209, 221, 224, 235, 243, 248, 253, 258, 279, 292, 340, 342, 353, 362, 383, 413, 429, 440, 488, 508, 529, 540, 584, 597, 611, 630, 651, 662, 679, 685, 704, 711, 718, 725, 732, 764, 782, 812
Offset: 1

Views

Author

Keywords

Comments

n such that A000030(A000142(n)) = 5. - Robert Israel, Feb 07 2017
The asymptotic density of this sequence is log_10(6/5) = 0.079181... (Kunoff, 1987). - Amiram Eldar, Jul 17 2020

Examples

			7 is a term since 7! = 5040 has the initial digit 5.
		

Crossrefs

For factorials with initial digit d (1 <= d <= 9) see A045509, A045510, A045511, A045516, A045517, A045518, A282021, A045519; A045520, A045521, A045522, A045523, A045525, A045526, A045527, A045528, A045529.

Programs

  • Maple
    filter:= proc(t) local tf;
    tf:= t!;
    floor(tf/10^ilog10(tf)) = 5
    end proc:
    select(filter, [$1..1000]); # Robert Israel, Feb 07 2017
  • Mathematica
    Select[ Range[ 850 ], IntegerDigits[ #! ] [[1]] == 5 & ]
  • PARI
    isok(n) = digits(n!)[1] == 5; \\ Michel Marcus, Feb 08 2017

Formula

A008905(a(n)) = 5. - Amiram Eldar, Jul 17 2020

A045525 Numbers k such that k! has initial digit '6'.

Original entry on oeis.org

3, 13, 18, 24, 43, 49, 72, 120, 130, 138, 174, 178, 182, 193, 203, 227, 263, 270, 290, 309, 311, 313, 315, 317, 319, 321, 355, 364, 371, 378, 390, 395, 400, 405, 418, 426, 437, 457, 460, 463, 466, 469, 491, 501, 511, 518, 525, 536, 555, 559, 563, 567, 571
Offset: 1

Views

Author

Keywords

Comments

The asymptotic density of this sequence is log_10(7/6) = 0.066946... (Kunoff, 1987). - Amiram Eldar, Jul 17 2020

Examples

			3 is a term since 3! = 6 has the initial digit 6.
		

Crossrefs

For factorials with initial digit d (1 <= d <= 9) see A045509, A045510, A045511, A045516, A045517, A045518, A282021, A045519; A045520, A045521, A045522, A045523, A045524, A045525, A045526, A045527, A045528, A045529. See also A000142, A008905.

Programs

  • Mathematica
    Select[ Range[ 600 ], IntegerDigits[ #! ] [ [1] ] == 6 & ]
  • PARI
    isok(n) = digits(n!)[1] == 6; \\ Michel Marcus, Feb 08 2017

Formula

A008905(a(n)) = 6. - Amiram Eldar, Jul 17 2020

A045526 Numbers k such that k! has initial digit '7'.

Original entry on oeis.org

6, 56, 80, 156, 161, 170, 186, 200, 230, 238, 277, 288, 305, 307, 323, 325, 327, 344, 385, 410, 451, 454, 472, 475, 504, 532, 547, 551, 575, 592, 601, 615, 645, 661, 697, 710, 724, 731, 790, 800, 811, 822, 848
Offset: 1

Views

Author

Keywords

Comments

The asymptotic density of this sequence is log_10(8/7) = 0.057991... (Kunoff, 1987). - Amiram Eldar, Jul 17 2020

Examples

			6 is a term since 6! = 720 has the initial digit 7.
		

Crossrefs

For factorials with initial digit d (1 <= d <= 9) see A045509, A045510, A045511, A045516, A045517, A045518, A282021, A045519; A045520, A045521, A045522, A045523, A045524, A045525, A045526, A045527, A045528, A045529. See also A000142, A008905.

Programs

  • Mathematica
    Select[ Range[ 900 ], IntegerDigits[ #! ] [[1]] == 7 & ]
  • PARI
    isok(n) = digits(n!)[1] == 7; \\ Michel Marcus, Feb 08 2017

Formula

A008905(a(n)) = 7. - Amiram Eldar, Jul 17 2020

A045527 Numbers k such that k! has initial digit '8'.

Original entry on oeis.org

14, 29, 31, 33, 40, 52, 60, 65, 71, 79, 121, 131, 145, 151, 246, 251, 256, 286, 303, 329, 346, 357, 373, 423, 434, 448, 478, 494, 543, 579, 610, 650, 678, 684, 703, 738, 746, 754, 771, 780, 810, 834, 847
Offset: 1

Views

Author

Keywords

Comments

The asymptotic density of this sequence is log_10(9/8) = 0.051152... (Kunoff, 1987). - Amiram Eldar, Jul 17 2020

Examples

			14 is a term since 14! = 87178291200 has the initial digit 8.
		

Crossrefs

For factorials with initial digit d (1 <= d <= 9) see A045509, A045510, A045511, A045516, A045517, A045518, A282021, A045519; A045520, A045521, A045522, A045523, A045524, A045525, A045526, A045527, A045528, A045529. See also A000142, A008905.

Programs

  • Mathematica
    Select[ Range[ 900 ], IntegerDigits[ #! ] [ [1] ] == 8 & ]
  • PARI
    isok(n) = digits(n!)[1] == 8; \\ Michel Marcus, Feb 08 2017

Formula

A008905(a(n)) = 8. - Amiram Eldar, Jul 17 2020

A045528 Numbers k such that k! has initial digit '9'.

Original entry on oeis.org

96, 97, 98, 99, 100, 101, 102, 103, 122, 139, 166, 190, 233, 241, 261, 268, 301, 331, 366, 380, 415, 431, 445, 481, 497, 514, 521, 583, 596, 624, 629, 634, 655, 672, 690, 716, 723, 762, 789, 799, 821, 833, 861, 897
Offset: 1

Views

Author

Keywords

Comments

The asymptotic density of this sequence is log_10(10/9) = 1 - log_10(9) = 0.045757... (A104140) (Kunoff, 1987). - Amiram Eldar, Jul 17 2020

Examples

			96 is a term since 96! = 9.916779... * 10^149 has the initial digit 9.
		

Crossrefs

For factorials with initial digit d (1 <= d <= 9) see A045509, A045510, A045511, A045516, A045517, A045518, A282021, A045519; A045520, A045521, A045522, A045523, A045524, A045525, A045526, A045527, A045528, A045529. See also A000142, A008905, A104140.

Programs

  • Mathematica
    Select[ Range[ 900 ], IntegerDigits[ #! ] [ [1] ] == 9 & ]
  • PARI
    isok(n) = digits(n!)[1] == 9; \\ Michel Marcus, Feb 08 2017

Formula

A008905(a(n)) = 9. - Amiram Eldar, Jul 17 2020

Extensions

More terms from Robert G. Wilson v, Jan 03 2001
Showing 1-10 of 29 results. Next