project euler problem #5

2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.

What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?

http://projecteuler.net/problem=5


highlight below for my solution:


#using a prime number set datastructure - https://gist.github.com/aausch/6709819
p = PrimeSet()

def min_product(n):
    n in p #initialize the PrimeSet with all primes less than n
    product = 1
    for prime in p:
        product = product * (prime ** (int(n ** (1.0/prime))))
    return product

print min_product(20)

(see also my solution to problem #3)


[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 )

Facebook photo

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

Connecting to %s