Skip to content

Instantly share code, notes, and snippets.

@juanmacuevas
Created June 11, 2015 15:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juanmacuevas/807cdb87b16848bb9186 to your computer and use it in GitHub Desktop.
Save juanmacuevas/807cdb87b16848bb9186 to your computer and use it in GitHub Desktop.
Calculate factors from the first X numbers
#!/usr/bin/python
def factors(n):
return set(reduce(list.__add__,([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0)))
def print_factors(f):
for i in f:
print "%2s" % (i),
print
def calculate_factors(x):
for i in range(1,x+1):
f = sorted(list(factors(i)))[1:]
print_factors(f)
calculate_factors(100)
@juanmacuevas
Copy link
Author

By looking at the numbers with more factors than the previous numbers i discovered a nice sequence called Highly composite numbers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment