Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143 ?
a=600851475143
i=2
while i<a :
if a%i==0:
a1=a/i
else :
i+=1
continue
n=2
while n<a1:
if a1%n==0 :
break
n+=1
if n==a1:
break
i+=1
print a1
@imran31415
Copy link

imran31415 commented Apr 30, 2013

why does mine take too long to produce an answer.... I tried it with smaller numbers and it seems to work. I would really appreciate the help as i dont understand what makes your code so much smoother than mine (besides the fact its shorter.

def isitprime(n):
k=2
while k<n/2:
if n%k!=0:
pass
else:
k="not prime"
break
k= k+1
if k!="not prime":
k="PRIME"
else:
k="NOT PRIME"
return k

def getprimefactors(n):
bigprime=0
k=n/2
while k>0:
if n%k==0:
a=n/k
if isitprime(a)=="PRIME" and a>bigprime:
bigprime=a
else:
pass
else: pass
k=k-1
print bigprime

print isitprime(6023)
getprimefactors(6023)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment