login
Smallest integer m such that !m begins with n in base 10.
0

%I #13 Feb 02 2017 18:59:11

%S 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,

%T 138,6,156,186,52,31,33,14,166,98,97,96,104,35,105,27,22,93,146,5,48,

%U 55,249,15,91,37,42,187,77,90,124,352,25,110,394,89,280,69,147

%N Smallest integer m such that !m begins with n in base 10.

%C !n is a subfactorial number (A000166).

%e Subfactorial(0) = 1 begins with 1, so a(1) = 0 ;

%e Subfactorial(3) = 2 begins with 2, so a(2) = 3 ;

%e Subfactorial(14) = 32071101049 begins with 3, so a(3) = 14.

%p for n from 1 to 100 do:l1:=length(n):i:=0:for m from 1 to 400 while(i=0)do:

%p 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:

%t 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 *)

%Y Cf. A000166, A018799.

%K nonn,base

%O 0,3

%A _Michel Lagneau_, Oct 14 2011

%E a(0)=1 prepended by _Alois P. Heinz_, Feb 02 2017