Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 27th, 2012  |  syntax: Python  |  size: 0.59 KB  |  hits: 25  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. k = 20
  2. from math import sqrt, pow
  3. def fact(n):
  4.  l = {}
  5.  i = 1
  6.  while (n > 1):
  7.   if n % (i+1) == 0:
  8.    n /= i+1
  9.    if (i+1) in l: l[i+1]+=1
  10.    else: l[i+1]=1
  11.    i = 0
  12.   i += 1
  13.  return l
  14.  
  15. l = []
  16. for i in xrange(k-2):
  17.  l.append(fact(i+2))
  18.  
  19. factors = set()
  20. for i in l:
  21.  for j in i: factors.add(j)
  22.  
  23. factors = list(factors)
  24. factors.sort()
  25.  
  26. maxfactors = {}
  27. for i in factors:
  28.  for j in l:
  29.   if i in j:
  30.    if i not in maxfactors: maxfactors[i]=j[i]
  31.    elif maxfactors[i]<j[i]: maxfactors[i]=j[i]
  32.  
  33. result = 1
  34. for i in maxfactors:
  35.  result *= int(pow(i,maxfactors[i]))
  36.  
  37. print result