Created
July 21, 2021 13:31
-
-
Save igorvanloo/09af70647bab37a4280fd74528fffc61 to your computer and use it in GitHub Desktop.
Prime Factors Function
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
| def prime_factors(n): | |
| factors = [] | |
| d = 2 | |
| while n > 1: | |
| while n % d == 0: | |
| factors.append(d) | |
| n /= d | |
| d = d + 1 | |
| if d*d > n: | |
| if n > 1: | |
| factors.append(n) | |
| break | |
| return factors |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment