Created
December 1, 2009 19:40
-
-
Save russelnickson/246566 to your computer and use it in GitHub Desktop.
The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143 ?
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
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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)