We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Manasa and Factorials
Manasa and Factorials
Sort by
recency
|
30 Discussions
|
Please Login in order to post a comment
a good article click
Hey , I am not sure what went wrong with this logic. it is giving time limit error for almost all the cases.https://calcularrfc.com.mx/ Any help would be appreciated
in the statement it is said that n<=1e16, but in the test cases there are values greater than that. maybe what was meant that n has at most 16 digits
Using Binary Search:
def solve(n): def count(x): res = 0 while x: t = x//5 res+=t x = t return res
There are floor(n/5) + floor(n/25) + floor(n/125)+... zeroes at the end of n! Since 1/5 + 1/25 + 1/125 + ... = 1/4, we would expect (4n!) to be a very good lower bound for our answer. Also, the number of zeroes in successive values of n! only increase when n is a multiple of five. Using those two facts, we can create a starting value that requires very few checks even when n is very large.