Skip to content

Instantly share code, notes, and snippets.

@oshea00
Last active January 26, 2017 07:55
Show Gist options
  • Save oshea00/3703abbecebd5ef3eeca482866dee99b to your computer and use it in GitHub Desktop.
Save oshea00/3703abbecebd5ef3eeca482866dee99b to your computer and use it in GitHub Desktop.
import math
def isprime(n):
if n == 2:
return True
if n == 3:
return True
if n % 2 == 0:
return False
if n % 3 == 0:
return False
i = 5
w = 2
while i * i <= n:
if n % i == 0:
return False
i += w
w = 6 - w
return True
num = 600851475143
#num = 6858
r = num
factors = []
root = (num/2)+1
i=2
while i < root+1:
if isprime((i)):
if r > 1:
while (r/i)*i == r:
r = (r/i)
factors.append(i)
else:
break
i += 1
if len(factors) == 0:
print("Number %d is prime" % num)
else:
print("Largest prime factor = %d" % factors[-1])
print(factors)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment