Created
January 21, 2015 03:28
-
-
Save ssanin82/80c14a1da38595350e41 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 defaultdict | |
def prime_factors(n): | |
if n < 2: | |
return None | |
d = defaultdict(lambda: 0) | |
i = 2 | |
while i <= n: | |
if n % i == 0: | |
d[i] += 1 | |
n /= i | |
i = 2 | |
else: | |
i += 1 | |
return d |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment