How do we calculate last 5-digits of 10**12 ignoring trailing zeros. The code i wrote works good until 10**8 and after that take ages.<br>The source of problem is Project Euler : <a href="http://projecteuler.net/index.php?section=problems&id=160">http://projecteuler.net/index.php?section=problems&id=160</a><br>
<br>The code is pasted here : <a href="http://paste.pocoo.org/show/139745/">http://paste.pocoo.org/show/139745/</a><br><br> 1 ''' <br>
2 For any N, let f(N) be the last five digits before the trailing zeroes in N!.<br> 3 For example,<br> 4 <br> 5 9! = 362880 so f(9)=36288<br> 6 10! = 3628800 so f(10)=36288<br> 7 20! = 2432902008176640000 so f(20)=17664<br>
8 <br> 9 Find f(1,000,000,000,000)<br> 10 '''<br> 11 def f(n):<br> 12 fac = 1<br> 13 i = 1<br> 14 #for i in range(1, n+1):<br> 15 while i < n + 1:<br> 16 fac = int(str(fac * i).strip('0')) % 100000<br>
17 i += 1<br> 18 return fac<br> 19 <br> 20 print f(1000000000000)<br><br>PS. hope posting algorithmic doubts will not be considered spamming :)<br><br>