Skip to content

Instantly share code, notes, and snippets.

@sfpprxy
Created March 8, 2016 19:49
Show Gist options
  • Save sfpprxy/be42673c526b44bb8355 to your computer and use it in GitHub Desktop.
Save sfpprxy/be42673c526b44bb8355 to your computer and use it in GitHub Desktop.
max_prime_factor
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