patternpythonModerate
Euler Project problem #3
Viewed 0 times
problemprojecteuler
Problem
Problem: What is the largest prime factor of the number 600851475143?
Hi, I'm really new with Python. Can anyone give me some feedback for this code? it seem to produce the correct answer
Hi, I'm really new with Python. Can anyone give me some feedback for this code? it seem to produce the correct answer
a=600851475143
x=2
while x<(a/x):
if a%x==0: a=a/x
else: x+=1
print aSolution
It produces the right answer in this particular case, but it wouldn't produce the right answer for all inputs. Consider
Is there any reason for using an
I'm not a Pythonista, but I'm pretty sure it's preferred style to put the
a=4. The first time you hit the while guard, x is 2 and a/x is 2, so it skips the loop and prints 4.Is there any reason for using an
op= construct for x+=1 but not for a=a/x?I'm not a Pythonista, but I'm pretty sure it's preferred style to put the
if and else blocks on a new line even if they're only one line long:if a%x==0:
a/=x
else:
x+=1Code Snippets
if a%x==0:
a/=x
else:
x+=1Context
StackExchange Code Review Q#155910, answer score: 10
Revisions (0)
No revisions yet.