Beispiel #1
0
def solve():
    result = 0 #@UnusedVariable
    start = time.clock()
    i = 0
    primes = {}
    truncatable_primes = []
    for i in range(0, 7):
        border = ['37']
        if i == 0:
            border = ['2357']
        digit_sets = border + i*['1379'] + border
        for digits in produce(digit_sets):
            number = "".join(digits)
            nums = sorted(set([int(n) for n in generate_left_truncated_string(number)] + [int(n) for n in generate_right_truncated_string(number)]))
            all_are_primes = True
            for n in nums:
                if n < 10:
                    continue
                try:
                    is_p = primes[n]
                except KeyError, e:
                    is_p = miller_rabin(n, 20)
                    primes[n] = is_p 

                if not is_p:
                    all_are_primes = False
            if all_are_primes:
                truncatable_primes.append(int(number)) 
Beispiel #2
0
def solve(n):
    # It is 999.999 > 9^5 + 9^5 + 9^5 + 9^5 + 9^5
    i=0
    m = range(10)
    
    numbers = []
    for i in range(1,7):
        for digits in produce([m]*i):
            sum_of_fifth_powers = sum([d**n for d in digits])
            number = int("".join([str(d) for d in digits]))
            if number > 1 and number == sum_of_fifth_powers:
                numbers.append(number)
    
    result = sum(set(numbers))
    print("The sum of all the numbers that can be written as the sum of fifth powers of their digits is %(result)d" % vars())
Beispiel #3
0
def solve(N):
    primes = find_product_primes_below(N)
    factors_set = [[n for n in powers_below(p, N, 1)] for p in primes]

    max_frac = 0.0
    max_number = 0
    for factors in produce(factors_set):
        n = product_of(factors)
        if n > N:
            continue
        phi = product_of([num - num/p for (num,p) in zip(factors, primes)])

        frac = float(n)/phi
        if frac > max_frac:
            print(n, frac, factors)
            max_frac = frac
            max_number = n
    return max_number