login
Final nonzero digit of n! in base 8.
16

%I #6 Sep 26 2018 22:20:18

%S 1,1,2,6,3,7,2,6,6,6,4,4,6,6,4,4,3,3,6,2,5,1,6,2,6,6,4,4,6,6,4,4,6,6,

%T 4,4,2,2,4,4,4,4,1,3,4,4,3,5,6,6,4,4,2,2,4,4,4,4,3,1,4,4,5,3,3,3,6,2,

%U 1,5,6,2,2,2,4,4,2,2,4,4,5,5,2,6,3,7,2,6,2,2,4,4,2,2,4,4,6,6,4,4

%N Final nonzero digit of n! in base 8.

%H Robert Israel, <a href="/A136695/b136695.txt">Table of n, a(n) for n = 0..10000</a>

%F From _Robert Israel_, Sep 26 2018: (Start)

%F If A011371(n) == 0 (mod 3) then a(n) = A049606(n) mod 8.

%F If A011371(n) == 1 (mod 3) then a(n) = 2*(A049606(n) mod 4).

%F If A011371(n) == 2 (mod 3) then a(n) = 4. (End)

%e 6! = 720 decimal = 1320 octal, so a(6) = 2.

%p P:= 1: E:= 0: a[0]:= 1:

%p for n from 1 to 100 do

%p v:= padic:-ordp(n,2);

%p P:= P*(n/2^v) mod 8;

%p E:= E + v;

%p if E mod 3 = 0 then a[n]:= P

%p elif E mod 3 = 1 then a[n]:= 2*(P mod 4)

%p else a[n]:= 4

%p fi

%p od:

%p seq(a[n],n=0..100); # _Robert Israel_, Sep 26 2018

%Y Cf. A000142, A136690, A136691, A136692, A136693, A136694, A136696, A008904, A136697, A136698, A136699, A136700, A136701, A136702.

%Y Cf. A011371, A049606.

%K base,easy,nonn

%O 0,3

%A _Carl R. White_, Jan 16 2008