Example #1
0
def answer():
    # Lower bound is 1487
    found = 0
    primes = primes_to(10000, 1487)
    for a in range(len(primes)):
        for b in range(a+1, len(primes)):
            prime_a = primes[a]
            prime_b = primes[b]
            c = prime_b + (prime_b - prime_a)
            if c < 10000 and is_prime(c):
                if is_perm(prime_a, prime_b) and is_perm(prime_a, c):
                    found = str(prime_a) + str(prime_b) + str(c)
                    break
        if found:
            break
    return found
Example #2
0
def answer():
    # ratios = []
    # for n in range(2, 10000000):
    #     # Euler's Product Formula
    #     primes = list(set(prime_factors(n)))
    #     product = 1
    #     for p in primes: 
    #         product *= (1 - (1/p))
    #     if is_perm(n, product*n):
    #         ratios.append(1/product)
    # return ratios.index(min(ratios)) + 2
    """
    The above solution would work, but it takes far longer than the minute required
    so the best is to analyze the code. It seems to minimize the ratio 1/product
    we should maximize the product and take advantage of the fact that it is the
    product of two large distinct primes close to the sqrt(10**7)
    """
    ratios = {}
    primes = primes_to(3800,2200)
    for a in range(len(primes)):
        for b in range(a+1, len(primes)):
            n = primes[a] * primes[b]
            if n < 10000000:
                phi = (primes[a] - 1) * (primes[b] - 1)
                ratio = n/phi
                if is_perm(n, phi):
                    ratios[ratio] = n
    return ratios[min(ratios.keys())]
Example #3
0
def answer():
    x = 100
    while True:
        if is_perm(x, 2*x) and is_perm(x, 3*x) and is_perm(x, 4*x) and is_perm(x, 5*x) and is_perm(x, 6*x):
            return x
        x += 1