A045547 Numbers whose factorial has '2' as its final nonzero digit.
2, 5, 6, 8, 14, 19, 34, 35, 36, 38, 40, 41, 43, 47, 50, 51, 53, 62, 67, 74, 84, 85, 86, 88, 90, 91, 93, 97, 109, 110, 111, 113, 115, 116, 118, 122, 129, 132, 145, 146, 148, 150, 151, 153, 162, 167, 174, 177, 180, 181, 183, 189, 194, 200, 201, 203, 212, 217
Offset: 1
Links
Programs
-
Maple
count:= 0: r:= 1: for n from 2 while count < 100 do r:= r*n; if r mod 10 = 0 then r:= r/10^padic:-ordp(r, 5) fi; if r mod 10 = 2 then count:= count+1; A[count]:= n fi; od: seq(A[i], i=1..100); # Robert Israel, Dec 16 2016
-
Mathematica
f[ n_Integer, m_Integer ] := (c = 0; p = 1; While[ d = Floor[ n/5^p ]; d > 0, c = c + d; p++ ]; Mod[ n!/10^c, m ] ); Select[ Range[ 250 ], f[ #, 10 ] == 2 & ] Join[{2},Select[Range[5,220],Most[Split[IntegerDigits[#!]]][[-1,1]] == 2&]] (* Harvey P. Dale, May 04 2016 *) f[n_] := Mod[6 Times @@ (Rest[ FoldList[{1 + #1[[1]], #2! 2^(#1[[1]] #2)} &, {0, 0}, Reverse[ IntegerDigits[n, 5]]]]), 10][[2]] (* after Jacob A. Siehler & Greg Dresden in A008904 *); f[0] = f[1] = 1; Select[ Range[150], f[#] == 2 &] (* Robert G. Wilson v, Dec 28 2016 *)
-
PARI
lnz(n)=if(n<2, return(1)); my(m=Mod(1,5)); for(k=2,n, m*=k/10^valuation(k,5)); lift(chinese(Mod(0,2),m)) is(n)=lnz(n)==2 \\ Charles R Greathouse IV, Dec 16 2016
-
PARI
list(lim)=my(v=List(),m=Mod(1,5)); for(k=2,lim, m*=k/10^valuation(k,5); if(m==2, listput(v, k))); Vec(v) \\ Charles R Greathouse IV, Dec 16 2016
-
Python
from functools import reduce from itertools import count, islice from sympy.ntheory.factor_ import digits def A045547_gen(startvalue=1): # generator of terms return filter(lambda n:2==reduce(lambda x,y:x*y%10,((1,1,2,6,4)[a]*((6,2,4,8)[i*a&3] if i*a else 1) for i, a in enumerate(digits(n,5)[-1:0:-1])))*6%10, count(max(startvalue,1))) A045547_list = list(islice(A045547_gen(),30)) # Chai Wah Wu, Dec 07 2023
Comments