from math import sqrt
def factors0(n): # http://stackoverflow.com/a/16007256/849891
while n > 1:
for i in range(2, n + 1):
if n % i == 0:
n /= i
yield i
break
def factors(n): # improve (cf. http://stackoverflow.com/a/15703327/849891)
j = 2
while n > 1:
for i in xrange(j, int(sqrt(n+0.05)) + 1):
if n % i == 0:
n /= i ; j = i
yield i
break
else:
if n > 1:
yield n; break
# factors0(9000009): [3,3,101,9901] 0.59s-8.6M
# factors( 9000009): [3,3,101,9901] 0.08s-8.7M
for factor in factors(25*27): # 600851475143999917 # [41, 37309, # 0.36s-8.7M
print factor # 392798360393] # 0.36s-8.7M
ZnJvbSBtYXRoIGltcG9ydCBzcXJ0CgpkZWYgZmFjdG9yczAobik6ICAgIyBodHRwOi8vc3RhY2tvdmVyZmxvdy5jb20vYS8xNjAwNzI1Ni84NDk4OTEKICAgIHdoaWxlIG4gPiAxOgogICAgICAgIGZvciBpIGluIHJhbmdlKDIsIG4gKyAxKToKICAgICAgICAgICAgaWYgbiAlIGkgPT0gMDoKICAgICAgICAgICAgICAgIG4gLz0gaQogICAgICAgICAgICAgICAgeWllbGQgaQogICAgICAgICAgICAgICAgYnJlYWsKCmRlZiBmYWN0b3JzKG4pOiAgICAjIGltcHJvdmUgKGNmLiBodHRwOi8vc3RhY2tvdmVyZmxvdy5jb20vYS8xNTcwMzMyNy84NDk4OTEpCiAgICBqID0gMgogICAgd2hpbGUgbiA+IDE6CiAgICAgICAgZm9yIGkgaW4geHJhbmdlKGosIGludChzcXJ0KG4rMC4wNSkpICsgMSk6CiAgICAgICAgICAgIGlmIG4gJSBpID09IDA6CiAgICAgICAgICAgICAgICBuIC89IGkgOyBqID0gaQogICAgICAgICAgICAgICAgeWllbGQgaQogICAgICAgICAgICAgICAgYnJlYWsKICAgICAgICBlbHNlOgogICAgICAgICAgICBpZiBuID4gMToKICAgICAgICAgICAgICAgIHlpZWxkIG47IGJyZWFrCgojIGZhY3RvcnMwKDkwMDAwMDkpOiAgWzMsMywxMDEsOTkwMV0gIDAuNTlzLTguNk0KIyBmYWN0b3JzKCA5MDAwMDA5KTogIFszLDMsMTAxLDk5MDFdICAwLjA4cy04LjdNCgpmb3IgZmFjdG9yIGluIGZhY3RvcnMoMjUqMjcpOiAgICMgNjAwODUxNDc1MTQzOTk5OTE3ICAjIFs0MSwgMzczMDksICAgICAgIyAwLjM2cy04LjdNIAogICAgcHJpbnQgZmFjdG9yICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAjICAgMzkyNzk4MzYwMzkzXSAgIyAwLjM2cy04LjdN