forked from Ouditchya/SPOJ
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FCTRL4.py
43 lines (38 loc) · 944 Bytes
/
FCTRL4.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# AC , ALGO : Maths, Big Integer.
# Helpful Link : http://oeis.org/A008904
# For any clarifications, contact me at : [email protected]
from sys import stdin
def exp( e ) :
x = 1
y = 2
while e :
if e % 2 == 1 :
x = x * y
y = y * y
e >>= 1
return x
fac = [1,1,2,6,24]
while True :
n = stdin.readline()
if n == '' :
break
n = int(n)
a = []
n1 = n
j = 0
if n1 == 1 :
print '1'
continue
while n1 >= 5 :
b = n1 % 5
a.append( b )
j += 1
n1 /= 5
a.append( n1 )
i = 0
ld = 1
while i <= j :
ld = ( ld * ( fac[a[i]] ) * ( exp( i * a[i] ) ) ) % 10
i += 1
ld = ( ld * 6 ) % 10
print ld