Last active
May 19, 2016 23:14
-
-
Save erdnaxeli/ea852a1d8f61b16f433b0147e778ced7 to your computer and use it in GitHub Desktop.
This file contains 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
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