Exemple #1
0
def buildDivList(n):
  total = 0
  #return a list of tuples containing (prime, #ofPrime) of intenger n
  pList = EulerSupport.countPrimeComponents(n)
  #print(pList)
  #Made nonlocal instead of passing result cause it made so sense to constantly pass a consistent variable
  result = []
  def recursiveCount(vals,total):
    nonlocal result
    #This would only happen if an empty array were passed
    if len(vals) > 0:
      prime, count = vals[0]
    else:
      return [1]
    for i in range(0, count+1):
      tempTotal = total
      tempTotal *= pow(prime,i)
      if (len(vals) == 1):
        result.append(tempTotal)
      else:
        recursiveCount(vals[1:],tempTotal)
    return
  recursiveCount(pList,1)
  #Trim off the last number even though itself is a divisor not valid for this problem
  #Technically last number will always be equal to n
  result = result[:-1]
  firstTotal = sum(result)
  #The ones that divisors sum to itself are not valid...
  if n == firstTotal:
    #total += firstTotal
    print("Onsie: %d"%firstTotal)
  #If its less than then we've already covered it  
  elif firstTotal > n:
    pList = EulerSupport.countPrimeComponents(firstTotal)
    result = []
    recursiveCount(pList,1)
    result = result[:-1]
    if sum(result) == n:
      total += n
      total +=firstTotal
      print ("Twosie: %d %d"%(n,firstTotal))
  return(total)
Exemple #2
0
def program(n):
    print("Result: %d" % n)
    for i in range(1, n + 1):
        result = EulerSupport.countPrimeComponents(i)
Exemple #3
0
def program(n):
  print("Result: %d"%n)
  for i in range (1,n+1):
    result = EulerSupport.countPrimeComponents(i)