Project Euler 3: (Iron)Python
- by Ben Griswold
In my attempt to learn (Iron)Python out in the open, here’s my solution for Project Euler Problem 3.
As always, any feedback is welcome.
# Euler 3
# http://projecteuler.net/index.php?section=problems&id=3
# The prime factors of 13195 are 5, 7, 13 and 29.
# What is the largest prime factor of the number
# 600851475143?
import time
start = time.time()
def largest_prime_factor(n):
max = n
divisor = 2
while (n >= divisor ** 2):
if n % divisor == 0:
max, n = n, n / divisor
else:
divisor += 1
return max
print largest_prime_factor(600851475143)
print "Elapsed Time:", (time.time() - start) * 1000, "millisecs"
a=raw_input('Press return to continue')