Home > ProjectEuler.Net, Python > Project Euler – Problem 5

Project Euler – Problem 5


Homepagehttp://projecteuler.net/problem=5

Problem:

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?

How I solve:
– Well, basically the LCM list for [1..20] divisibility is: [11..20], not yet, since 14, 16, 18 are divisible by two, I take 2 * 2 down; also 12 and 20 are un-needed, take 3 down from 15. So the final list is: [11, 12, 13, 14, 15, 16, 17, 18, 19] / (3 * 4 * 12). This is the target calculation.


lcm_list = [11, 12, 13, 14, 15, 16, 17, 18, 19]

res = 1
for x in lcm_list:
	res *= x

print res / (3 * 4 * 12)

Cheers,
Pete Houston

Advertisements
Categories: ProjectEuler.Net, Python Tags: , ,
  1. No comments yet.
  1. No trackbacks yet.

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

%d bloggers like this: