예제 #1
0
def euler0023(n): # n must be nothing in order to solve the problem
  """ Find the sum of all the positive integers which cannot be written as the sum of two abundant numbers. """
  abundants = []
  sumOfAbundants = []
  answer = 0
  for x in range(1,28126):
    mult = (euler.mult(x))[:-1]
    sumM = sum(mult)
    state = ''
    if   sumM >  x: 
      state = 'abundant'
      abundants.append(x)
    elif sumM == x: state = 'perfect'
    elif sumM <  x: state = 'deficient'
    print x,mult,'<>',sumM,state
  for x in abundants:
    print x
    for xx in abundants:
      sumOfAbundants.append(x+xx)
  abundants = ''
  for x in range(1,28126):
    print x
    if x not in sumOfAbundants:
      answer += x
  return answer
예제 #2
0
def euler0010(n): # n must be 2000000 in order to solve the problem
  """ Calculate the sum of all the primes below two million. """
  R = 0
  for i in range(2,n):
    mult = euler.mult(i)
    if len(mult) < 3:
      R+=i
      print i,mult,R
  return R
예제 #3
0
def euler0012(n): # n must be 500 in order to solve the problem
  """ What is the value of the first triangle number to have over five hundred divisors? """
  a,c,M = 0,0,0
  while True:
    a += 1
    c += a
    f = len(euler.mult(c))
    if f > M:
      M = f
      print a,c,M
    if M > n:
      return a,c,M
예제 #4
0
def euler0021(n): # n must 10000 in order to solve the problem
  """ Evaluate the sum of all amicable pairs under 10000. """
  if n < 220: return 'the smallest number is over 220. So please... '
  Mtmp = []
  pmtM = []
  for x in range(220,n):
#    print (euler.mult(x))
    Mtmp.append([x,sum((euler.mult(x))[:-1])])
    pmtM.append(Mtmp[-1][::-1])
  R = []
  for x in Mtmp:
    if x!=x[::-1] and x in pmtM and x[::-1] not in R: R.append(x)
  print Mtmp
  print 'and'
  print pmtM
  return R,sum([xx for x in R for xx in x])
예제 #5
0
def euler0003(n): # n must be 600851475143 in order to solve the problem
  """ Find the largest prime factor of a composite number. """
  return ([x for x in euler.mult(n) if euler.prime(x)])
예제 #6
0
 def setMult(n): global m ; m = euler.mult(n) ; return 1
 return sum([x for x in range(n) if setMult(x) and (3 in m or 5 in m)])