Last non-zero

In decimal representation, find the last non-zero digit of 2015 ! 2015! .

Clarification : It is 2015 factorial.

4 6 8 2

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

1 solution

Abdelhamid Saadi
Aug 3, 2015

From this link , we have If D ( N ) D(N) denotes the last non zero digit of factorial, then

D ( N ) = 4 D ( N 5 ) D ( Units digit of $N$ ) (If tens digit of $N$ is odd) D(N)=4D\left(\left\lfloor{\frac N5}\right\rfloor\right)\cdot D(\mbox{Units digit of \$N\$}) \qquad \mbox{(If tens digit of \$N\$ is odd)} D ( N ) = 6 D ( N 5 ) D ( Units digit of $N$ ) (If tens digit of $N$ is even) D(N)=6D\left(\left\lfloor{\frac N5}\right\rfloor\right)\cdot D(\mbox{Units digit of \$N\$}) \qquad \mbox{(If tens digit of \$N\$ is even)}

Where \left\lfloor\cdots\right\rfloor is greatest integer function.

This can be coded in python 3.4 like this:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
Dsmall = [1, 1, 2, 6, 4, 2, 2, 4, 2 , 8]

def D(n):
    "Last non-zero"
    if n < 10:
        return Dsmall[n]
    elif (n//10)%2 == 0:
        return (4*D(int(n/5))*Dsmall[n%10])%10
    else:
        return (6*D(int(n/5))*Dsmall[n%10])%10

print(D(2015))

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...