# Re: sorry, possibly too much info. was: Re: How can I speed up a script that iterates over a large range (600 billion)?

::sigh:: Well, I'm stuck again and it has to do with my get_factors
function again, I think. Even with the slight optimization, it's
taking forever on 20! (factorial, not excitement) :) It's frustrating
because I have the Python right, but I'm getting stuck on the math.

The problem:

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

Here's the function (it's in the problem3.py file, hence the import
below):

import math

def get_factors(number):
factors = []

for n in range(2, int(math.sqrt(number))):
if number % n == 0:
factors.append(n)
factors.append(number // n)

return factors

And here's my new script for the new exercise:

import math
from problem3 import get_factors

max_num = 20
n = math.factorial(max_num)
factors = get_factors(n)
div_all = []

for x in factors:
for y in range(2, max_num+1):
if x % y != 0:
break
elif y == max_num:
div_all.append(x)

print(min(div_all))

It could easily be that I'm simply approaching it all wrong. I just
thought that maybe using the factorial of the highest number in the
range (in this case, 20) would be an easy way of finding which numbers
to test.
.

• Follow-Ups:
• References:

## Relevant Pages

• Re: Python Math libraries - How to?
... I am teaching myself Python following free tutorials. ... uses a "import math" statement to calculate a square root. ... # A program to compute the volume and surface area of a sphere ...
(comp.lang.python)
• Re: math.nroot [was Re: A brief question.]
... > that's portable across platforms and versions of python? ... could we perhaps have some constants in the math module for them? ... ValueError: math domain error ... program error than intent for most applications. ...
(comp.lang.python)
• Re: cos: "Integer Required"?!?!?!?
... I input something incorrect as an argument to an xplane sdk function ... I wonder if the XPlane SDK Python ... I'll download the latest ActiveState Python and keep on plugging. ... Am I totally missing something about 'math'. ...
(comp.lang.python)
• Re: OT: excellent book on information theory
... margin, or better to a separate latech document, suitable for those ... A separate Python library would be handy too, and if not in the main ... > I also don't think presenting the math in Python would make things any ... but the algorithms source codes are. ...
(comp.lang.python)
• Re: Newbie look at Python and OO
... in several languages, just learning Python. ... Actually, binding to numbers works just the same as for lists, ... countin the math module? ... Name binding can seem confusing at first, ...
(comp.lang.python)