[Tutor] To find the least number divisible by all numbers from 1-20

Marc Tompkins marc.tompkins at gmail.com
Tue Aug 13 19:14:51 CEST 2013


On Tue, Aug 13, 2013 at 9:45 AM, #PATHANGI JANARDHANAN JATINSHRAVAN# <
JATINSHR001 at e.ntu.edu.sg> wrote:

>  Hello All,
>
> Sorry for the earlier mail without subject. I was in a hurry so I missed
> that
>
>  I am solving problem number 5 in project euler. I think my solution
> seems logically correct but it is not giving an answer as it is taking too
> long to execute. So can someone suggest an alternative solution?
>

My approach: factor each number from 1 to 20 (for example, 20 factors to 1,
2, 2, 5) and build a list of factors; for each number, check to see that
the list contains enough copies of all of the current number's factors
(e.g. four 2s and two 3s) and add them to the list if not; at the end,
multiply the list of factors.

It took me about a minute in Excel; about 45 minutes to work out my
algorithm in Python - but it executed in less than a second.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20130813/e24ca640/attachment-0001.html>


More information about the Tutor mailing list