python - My ProjectEuler implementation is much too slow -
this question has answer here: smallest positive number evenly divisible of numbers 1 20? 5 answers these problem: 2520 smallest number can divided each of numbers 1 10 without remainder. smallest positive number evenly divisible of numbers 1 20? these solution, takes lot of time! x = 0 check = [11, 13, 14, 16, 17, 18, 19, 20] while true: x += 1 if all(x % j == 0 j in check): print "the number is", x break print x how improve it? counter main problem? or while? edit: i've seen there lot of differente solutions, should check every single number 1 , without function lcm? this implementation c++ program. instead of number++ , go number += 2 , why? because odd number never divisible 2 therefore reducing search space o(n) o(n/2) . there 1 more way reduce space search, shifting code number += 20 (limit)...