Last non-zero digit of n! Given an integer 1 ≤ N ≤ 1,000,000 as input, output the last non-zero digit of N!, where ! is the factorial (the product of all numbers from 1 to N, inclusive).  This is OEIS sequence A008904.

Your program needs finish within 10 seconds on a reasonable machine for any valid input.

Test Cases

1 =&gt; 1
2 =&gt; 2
3 =&gt; 6
4 =&gt; 4
5 =&gt; 2
6 =&gt; 2
7 =&gt; 4
8 =&gt; 2
9 =&gt; 8
10 =&gt; 8
100 =&gt; 4
1000 =&gt; 2
10000 =&gt; 8
100000 =&gt; 6
1000000 =&gt; 4


This is a code-golf so the shortest code in bytes wins!
Mathematica, 45 36 bytes

Last@Select[IntegerDigits[#!],#&gt;0&amp;]&amp;


Very readable for a winning answer. :) (Then again, there's no GolfScript &amp; Co. submission yet.)

This handles input 1,000,000 in about 5 seconds on my machine.