Skip to content

Instantly share code, notes, and snippets.

@erdnaxeli
Last active May 19, 2016 23:14
Show Gist options
  • Save erdnaxeli/ea852a1d8f61b16f433b0147e778ced7 to your computer and use it in GitHub Desktop.
Save erdnaxeli/ea852a1d8f61b16f433b0147e778ced7 to your computer and use it in GitHub Desktop.
def primal(n):
factors = []
d = 2
while n > 1:
while n % d == 0:
factors.append(d)
n = n / d
d += 1
return factors
if __name__ == '__main__':
factors = {}
i = 0
while i <= 20:
tmp_factors = {}
for f in primal(i):
tmp_factors[f] = tmp_factors.get(f, 0) + 1
for f in tmp_factors:
count = tmp_factors[f]
if count > factors.get(f, 0):
factors[f] = count
i += 1
print(factors)
total = 1
for f in factors:
count = factors[f]
total *= f**count
print total
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment