Created
May 19, 2018 22:57
-
-
Save accessnash/e54b671ab5373d93a31058ae861182b2 to your computer and use it in GitHub Desktop.
Project Euler problem 3 - to find the largest prime factor of a given number
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 max_prime_factor(n): | |
| i = 2 | |
| pfactors = [] | |
| while i * i <= n: | |
| if n % i: | |
| i += 1 | |
| else: | |
| n //= i | |
| pfactors.append(i) | |
| if n > 1: | |
| pfactors.append(n) | |
| return max(pfactors) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment