def main():
    x = min(
        ((p, q) for p, q in prime_pairs(list(primes(LIMIT // 2)))
         if is_permutation(phi(p, q), p * q)),
        key=lambda x: x[0] * x[1] / phi(x[0], x[1]),
    )
    return x[0] * x[1]
Ejemplo n.º 2
0
def main():
    ps = set(primes(10**6))
    count = 0
    for p in ps:
        if all(int(r) in ps for r in rotations(str(p))):
            count += 1
    return count
Ejemplo n.º 3
0
def very_prime_divisible(n):
    v, prime = 1, primes(n)
    while True:
        p = next(prime)
        if p * v > n:
            return v
        else:
            v *= p
def find_smallest_member(matches):
    bound = 2
    while True:
        ps = set(primes(10**bound))
        for pattern in (int_to_pattern(n) for n in range(1, 11**bound)):
            prime_replacements = {n for n in expand(pattern) if n in ps}
            if len(prime_replacements) == matches:
                return min(prime_replacements)
        bound += 1
Ejemplo n.º 5
0
def minimum_counter_example():
    bound, composites, sums = 2, set(), set()
    while not composites - sums:
        ps = set(primes(bound))
        composites = {n for n in range(2, bound) if n % 2 != 0} - ps
        sums = {
            p + 2 * n**2
            for p in ps for n in range(floor(sqrt(bound / 2)) + 1)
        }
        bound *= 2
    return min(composites - sums)
Ejemplo n.º 6
0
def main():
    global pl, ps
    pl = list(primes(LIMIT))
    ps = set(pl)

    candidates = ((pl[a], pl[b], pl[c], pl[d], pl[e]) for a in range(len(pl))
                  for b in range(a) if is_compatable(pl[a], pl[b])
                  for c in range(b) if all(
                      is_compatable(pl[x], pl[c]) for x in [a, b])
                  for d in range(c) if all(
                      is_compatable(pl[x], pl[d]) for x in [a, b, c])
                  for e in range(d) if all(
                      is_compatable(pl[x], pl[e]) for x in [a, b, c, d]))

    return sum(next(candidates))
Ejemplo n.º 7
0
def main():
    four_digit_primes = {p for p in primes(10000) if p >= 1000}

    prime_permutation_sequences = (
        [p, p + k, p + 2 * k]
        for p in four_digit_primes
        for k in range(2, (10000 - p) // 2 + 1)
        if are_prime_permutations(four_digit_primes, p, p + k, p + 2 * k)
    )

    return next(
        n
        for n in (
            "".join(str(p) for p in s) for s in prime_permutation_sequences
        )
        if n != "148748178147"
    )
Ejemplo n.º 8
0
def main():
    LIMIT = 5 * 10 ** 7

    ps = list(primes(round(sqrt(LIMIT))))
    expressible = set()

    for p2 in ps:
        if f(p2, 2, 2) >= LIMIT:
            break
        for p3 in ps:
            if f(p2, p3, 2) >= LIMIT:
                break
            for p4 in ps:
                if f(p2, p3, p4) >= LIMIT:
                    break
                expressible.add(f(p2, p3, p4))

    return len(expressible)
def main():
    return sum(primes(2 * 10**6))
def main():
    global ps
    ps = list(primes(5000))
    return next(n for n in count() if decompositions(n) - 1 > 5000)
def main():
    return sum(truncatable_primes(set(primes(10 ** 6))))