Python Project Euler 3 -
i'm new python, i'm trying girlfriend learn coding through project euler, suggested start python. unfortunately on problem 3 came strange error.
for finding prime factors of smaller numbers, seems work fine, trying find prime factors of 600851475143 chokes.
i under impression python extremely forgiving maximum integer values, don't know why doesn't work here.
def is_prime (n) : in range (2, n) : if n % == 0: return 0 return 1 n = 600851475143 in range (1, n) : if n % == 0 : if is_prime (i) == 1 : print
if lead me right, i'd thankful!
david
edit: i'm aware how sub-optimal is!
since no 1 answered obvious, use xrange
instead of range
:
def is_prime (n) : in xrange (2, n) : if n % == 0: return 0 return 1 n = 600851475143 in xrange (1, n) : if n % == 0 : if is_prime (i) == 1 : print
but keep in mind still slow, won't run memoryerrors.
Comments
Post a Comment