Ejemplo n.º 1
0
print 'fractions are'
print '\n'.join( [str(a) + '/' + str(b) for a, b in fractions] )


product = [1, 1]
for a, b in fractions:
  product[0] *= a
  product[1] *= b

from lib import euler

# now simplify the product

while 1:
  a_divisors = euler.divisors(product[0])
  b_divisors = euler.divisors(product[1])
  brk = False
  for d in a_divisors[::-1]:
    if d in b_divisors:
      #print 'dividing by', d
      if d == 1:
        brk = True
        break
      else:
        product = [product[0]/d, product[1]/d]
        #print product
        break
  if brk:
    break
Ejemplo n.º 2
0
"""Evaluate the sum of all the amicable numbers under 10000."""

from lib import euler

d = lambda x: sum(euler.divisors(x)[:-1])

amicables = []
for a in xrange(1, 10000):
  b = d(a)
  if b != a and d(b) == a: amicables += [a, b]

# might be some duplication
print sum(list(set(amicables)))
Ejemplo n.º 3
0
def is_abundant(n):
  # special case
  if n<=1: return False
  divisors = euler.divisors(n)[:-1]
  return sum(divisors) > n