from math import * from black_box import alldivs sums = [] tobe = [] a = range(1,10001) for i in a: summ = sum(alldivs(i)) if summ < 10000 and sum(alldivs(summ)) == i: sums.append([i, summ]) if i!= summ: tobe.append(i) answer = sum(tobe) print(sums) print(answer)
#What is the value of the first triangle number to have over five hundred divisors? from black_box import alldivs from black_box import numdivs done = False thisTri = 1 increment = 1 divListSizeMax = 0 while not done: allDivs = [] divListSize = 0 increment += 1 thisTri += increment divList = alldivs(thisTri) divListSize = len(divList) if(divListSize >= divListSizeMax): divListSizeMax = divListSize print("--") print(increment) print(thisTri) print(divListSizeMax) if(divListSize >= 500): done = True print(increment) print(thisTri) print(divListSize)
#Find the sum of all the positive integers which cannot be written as the sum #of two abundant numbers. from math import * from black_box import alldivs upperLimit = 28123 abundants = [] #find all the abundant numbers up to the upperlimit for i in range(upperLimit): if(i%1000 == 0): print('{0:.2f}'.format(100 * i / upperLimit)) allTheseDivs = [] allTheseDivs = alldivs(i) thisSum = sum(allTheseDivs[0:-1]) if(thisSum > i): abundants.append(i) print(abundants[0]) #SAVING TO FILE _______________________________________ file = open("../Reference/abundants.txt", "w") for num in abundants: file.write(str(num) + " ") file.close() #___________________________________
def commonFactors(newNumber, currentFactors): newFact = alldivs(newNumber) intersection = list(set(currentFactors) & set(newFact)) return intersection
#recursive function def fourPrimeFacts(mainNumber, numSoFar, factors): for num in factors: newMain = mainNumber / num commonFact = commonFactors(newMain, factors) found = False num = 1 while not found: factors = alldivs(num) if(len(factors) >= 4): primeFactors = [] for fact in factors: if(isprime(fact)): primeFactors.append(fact) #have list of all prime factors if(len(primeFactors) >=4): #At this point, I need to see if any combination #of 4 of these will result in our num #if i divide by one of them, and the result still has at least three of the others as factors, I can keep going
# The prime factors of 13195 are 5, 7, 13 and 29. # What is the largest prime factor of the number 600851475143 ? from black_box import isprime from black_box import alldivs divList = alldivs(600851475143) answer = divList[-1] for num in reversed(divList): if(isprime(num)): answer = num break print(answer)