Sort by

recency

|

30 Discussions

|

  • + 0 comments

    a good article click

  • + 0 comments

    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

  • + 0 comments

    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

  • + 0 comments

    Using Binary Search:

    def solve(n): def count(x): res = 0 while x: t = x//5 res+=t x = t return res

    l,r = 5,5*(10**16)
    res = 5
    while l<=r:
        mid = (l+r)//2
        if count(mid)>=n:
            res = mid
            r = mid - 1
        else:
            l = mid + 1
    return res 
    
  • + 3 comments

    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.

    def fact_zeros(n):
        count = 0
        while n:
            count += n//5
            n //= 5
        return count
    
    def solve(n):
        test = ((4*n)//5) * 5
        while fact_zeros(test) < n:
            test += 5
        return test