Last active
July 31, 2017 05:09
-
-
Save junjiah/c07ba926ced59babde5b0ce1bc893fad to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import Counter | |
from math import log | |
def prime_fac(x): | |
"""Returning a map factor -> exponent.""" | |
c = Counter() | |
for i in xrange(2, x + 1): | |
while x % i == 0: | |
c[i] += 1 | |
x //= i | |
return c | |
def zeroes(base, n): | |
factor_cnts = prime_fac(base) | |
cnts = Counter() | |
# Find number of factors for the whole factorial. | |
for f in factor_cnts: | |
cnts[f] =sum(n // (f ** i) for i in xrange(1, int(log(n, f) + 1))) | |
return min(cnts[k] // factor_cnts[k] for k in factor_cnts) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment