Created
March 8, 2016 19:49
-
-
Save sfpprxy/be42673c526b44bb8355 to your computer and use it in GitHub Desktop.
max_prime_factor
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
import math | |
def is_prime(n): | |
return not [i for i in range(2, int(math.sqrt(n)) + 1) if n % i == 0] | |
def max_prime_factors(n): | |
x = [i for i in range(2, int(math.sqrt(n)) + 1) | |
if is_prime(i) and n % i == 0] | |
y = [n / i for i in x if i not in x and is_prime(n / i)] | |
if not sum([x, y], []): | |
return -1 | |
else: | |
return max(sum([x, y], [])) | |
answer = max_prime_factors(600851475143) | |
print(answer) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment