Example #1
0
def get_sum_of_divisors(primes, n):
    prime_factors = []
    euler_base.get_prime_factors(primes, prime_factors, n)
    divisors = euler_base.get_divisors(prime_factors, n, include_n=False)
    divisors.sort()
    # print "n: %d, divisors: %s" % (n, divisors)
    return sum(divisors)
Example #2
0
def main():
    """ 
    600851475143 = 71* 839* 1471* 6857
    """
    if len(sys.argv) < 2:
        usage()
        sys.exit(0)

    start = time.time()

    n = int(sys.argv[1])
    primes = euler_base.get_primes_to_sqrt_n(n)

    prime_factors = []
    euler_base.get_prime_factors(primes, prime_factors, n)
    print "%d has prime factors: %s" % (n, prime_factors)
Example #3
0
        return previous_tn + n

def main():
    """ 
    What is the value of the first triangle number to have over five hundred divisors?
    The 12375th triangle number: 76576500, has 575 divisors
    found solution in 35.4850001335 seconds
    """
    if len(sys.argv) < 2:
        usage()
        sys.exit(0)
    start = time.time()
    n = int(sys.argv[1])

    i = 1
    tn = 1  # initial triangle number value
    primes_step = 100

    primes = []
    euler_base.get_nth_prime(primes, primes_step) # populate array of primes to start with
    
    while True:
        tn = get_nth_triangle_number(tn, i)
        min_prime_number = int(math.sqrt(tn))
        while primes[-1] < min_prime_number:
            # get more primes as needed
            euler_base.get_nth_prime(primes, len(primes) + primes_step)

        # determine the factors of tn that are prime numbers
        prime_factors = []
        euler_base.get_prime_factors(primes, prime_factors, tn)
        # print "tn: %d, prime_factors: %s" % (tn, prime_factors)

        # use list of primes to determine all divisors of tn
        divisors = euler_base.get_divisors(set(prime_factors), tn, include_n=True)
        # print "divisors: %s" % divisors
        
        if len(divisors) > n: