project euler problem #3

The prime factors of 13195 are 5, 7, 13 and 29.

What is the largest prime factor of the number 600851475143 ?

http://projecteuler.net/problem=3


highlight below for my solution:


#using a prime number set datastructure - https://gist.github.com/aausch/6709819
p_set = PrimeSet()
n = 600851475143
sqrt = int(n ** 0.5) 
p_set[sqrt]
max_factor = 1
for x in p_set:
    if n % x == 0 and x > max_factor:
        max_factor = x       
print max_factor


[More programming riddles]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s