Exemplo n.º 1
0
#
# Let us list the factors of the first seven triangle numbers:
#
#  1: 1
#  3: 1,3
#  6: 1,2,3,6
# 10: 1,2,5,10
# 15: 1,3,5,15
# 21: 1,3,7,21
# 28: 1,2,4,7,14,28
#
# We can see that 28 is the first triangle number to have over five
# divisors.
#
# What is the value of the first triangle number to have over five
# hundred divisors?

import eutils.factors as factors
import time
start = time.time()

tri = [2, 3]
while len(factors.l_factors(tri[1])) < 500:
    tri[0] += 1
    tri[1] += tri[0]

ans = tri[1]

end = time.time()
print("The answer to Problem 12 is: %s" % ans)
print("<< Returned in %s seconds >>" % (end - start))
Exemplo n.º 2
0
# Problem 3
#
# The prime factors of 13195 are 5, 7, 13 and 29.
#
# What is the largest prime factor of the number 600851475143?

import eutils.factors as factors
import eutils.primes as primes
import time
start = time.time()

ans = None
fac = factors.l_factors(600851475143)

i = len(fac) - 2
while ans is None:
    if primes.is_prime(fac[i]):
        ans = fac[i]
    i -= 1

end = time.time()
print("The answer to Problem 3 is: %s" % ans)
print("<< Returned in %s seconds >>" % (end - start))
Exemplo n.º 3
0
#
# As 12 is the smallest abundant number, 1 + 2 + 3 + 4 + 6 = 16, the
# smallest number that can be written as the sum of two abundant numbers
# is 24. By mathematical analysis, it can be shown that all integers
# greater than 28123 can be written as the sum of two abundant numbers.
# However, this upper limit cannot be reduced any further by analysis
# even though it is known that the greatest number that cannot be
# expressed as the sum of two abundant numbers is less than this limit.
#
# Find the sum of all the positive integers which cannot be written as
# the sum of two abundant numbers.

import eutils.factors as factors
import eutils.vectorize as vec
import time
start = time.time()

abun = []
for n in range(1, 28124):
    if n < vec.v_sum(factors.l_factors(n)[:-1]):
        abun.append(n)

n = list(range(1,28124))
able = [x + y for i, x in enumerate(abun) for y in abun[i:]]
able = dict(zip(able, [0] * len(able)))

ans = vec.v_sum([y for y in n if y not in able])

end = time.time()
print("The answer to Problem 23 is: %s" % ans)
print("<< Returned in %s seconds >>" % (end - start))