A197423 Smallest integer m such that !m begins with n in base 10.
1, 0, 3, 14, 5, 25, 69, 16, 20, 4, 34, 28, 41, 9, 8, 53, 73, 12, 7, 38, 46, 81, 13, 18, 120, 138, 6, 156, 186, 52, 31, 33, 14, 166, 98, 97, 96, 104, 35, 105, 27, 22, 93, 146, 5, 48, 55, 249, 15, 91, 37, 42, 187, 77, 90, 124, 352, 25, 110, 394, 89, 280, 69, 147
Offset: 0
Examples
Subfactorial(0) = 1 begins with 1, so a(1) = 0 ; Subfactorial(3) = 2 begins with 2, so a(2) = 3 ; Subfactorial(14) = 32071101049 begins with 3, so a(3) = 14.
Programs
-
Maple
for n from 1 to 100 do:l1:=length(n):i:=0:for m from 1 to 400 while(i=0)do: s:=0:for j from 0 to m do: s:=s+m!*(((-1)^j)*1/j!) :od:x:=s:l:=length(x):y:=floor(x/(10^(l-l1))):if y=n and l>=l1 then i:=1: printf ( "%d %d \n",n,m): else fi:od:od:
-
Mathematica
f[n_] := Block[{k = 0, m}, While[m = Max[0, Floor@Log[10, Subfactorial[k]] - Floor@Log[10, n]]; (Subfactorial[k] - Mod[Subfactorial[k], 10^m])/10^m! = n, k++]; k]; Array[f, 67] (* program from David W. Wilson - see A018799 Nov 05 2010 *)
Extensions
a(0)=1 prepended by Alois P. Heinz, Feb 02 2017
Comments