def distinctPrimeFactors(n): div = divisors(n) div.remove(1) toRemove = set() [toRemove.add(d) for d in div if not isPrime(d)] return div - toRemove
#============================================================================== # Evaluate the sum of all the amicable numbers under 10000. #============================================================================== from Common import divisors total = 0 for a in range(1, 10000): b = sum(divisors(a)) - a if sum(divisors(b)) - b == a and not a == b: total += a print(total)
#=============================================================================== # What is the largest prime factor of the number 600851475143 ? #=============================================================================== from Common import isPrime, divisors print(max([i for i in divisors(600851475143) if isPrime(i)]))
#=============================================================================== # What is the value of the first triangle number to have over five hundred divisors? #=============================================================================== from Common import divisors, trianglenum i = 1 while True: if len(divisors(trianglenum(i))) > 500: break i += 1 print(trianglenum(i))
#=============================================================================== # Find the sum of all the positive integers which cannot be written as the sum of two abundant numbers. #=============================================================================== from Common import divisors bound = 28123 abundants = [] [abundants.append(i) for i in range(1, bound) if sum(divisors(i)) - i > i] sums = set() high = 0 length = len(abundants) for i in range(length): high = 0 j = i; while high < bound and j < length: summed = abundants[i] + abundants[j] sums.add(summed) high = summed j += 1 if abundants[i] * 2 >= bound: break print(sum(set(range(1, bound)) - sums))