Beispiel #1
0
def ans():
    size = 5
    skip_to = 8300
    for p in Prime.gen_nums():
        if p < skip_to:
            continue
        nums = [q for q in Prime.gen_nums(p) if compatible(q, p)]
        for tuple_ in combinations(nums, size - 1):
            if remarkable(tuple_):
                return p + sum(tuple_)
Beispiel #2
0
def ans():
    for prime in Prime.gen_nums():
        if prime < 120000:
            continue

        # Replace all combinations of digits
        list_ = list(str(prime))
        length = len(list_)
        for count in range(length):
            combs = combinations(range(length), count)
            for indices in combs:

                # Count the number of primes by replacing
                # the selected digits with some other digit
                generated_primes = set()
                for replacement in range(10):
                    copy = list_.copy()
                    for i in indices:
                        copy[i] = str(replacement)
                    number = int(''.join(copy))
                    if Prime.contains(number):
                        generated_primes.add(number)

                if 7 < len(generated_primes):
                    return min(generated_primes)
Beispiel #3
0
def ans():
    truncatable = set()
    for p in Prime.gen_nums():
        if is_truncatable(p):
            truncatable.add(p)
        if len(truncatable) == 11:
            break
    return sum(truncatable)
Beispiel #4
0
def ans():
    n = 1
    for p in Prime.gen_nums():
        next_ = n * p
        if 1000000 < next_:
            return n
        n = next_
    return n
Beispiel #5
0
def ans():
    groups = defaultdict(set)
    for prime in Prime.gen_nums(10000):
        groups[''.join(sorted(str(prime)))].add(prime)
    for set_ in groups.values():
        for comb in combinations(set_, 3):
            seq = sorted(list(comb))
            if seq[0] < 1000:
                continue
            if (seq[2] + seq[0] == 2 * seq[1] and seq[0] != 1487):
                return ''.join(str(n) for n in seq)
Beispiel #6
0
def ans():
    prime_list = list(Prime.gen_nums(4000))
    longest = (0, 0)
    for i in range(len(prime_list)):
        sum_ = 0
        for j in range(i, len(prime_list)):
            sum_ += prime_list[j]
            if 1000000 <= sum_:
                break
            if Prime.contains(sum_) and longest[1] < j - i + 1:
                longest = (sum_, j - i + 1)
    return longest[0]
Beispiel #7
0
def ans():
    divisors = list(Prime.gen_nums(18))
    sum_ = 0
    for p in gen_pandigitals(from_=0, to=9):
        has_property = True
        for i in range(1, 8):
            dividend = int(str(p)[i:i + 3])
            if dividend % divisors[i - 1] != 0:
                has_property = False
                break
        if has_property:
            sum_ += p
    return sum_
Beispiel #8
0
def ans():
    circular_primes = set([2])
    for p in Prime.gen_nums(1000000):
        if any(x in str(p) for x in '02468'):
            continue
        is_circular = True
        for i in range(len(str(p))):
            if not Prime.contains(int(str(p)[i:] + str(p)[:i])):
                is_circular = False
                break
        if is_circular:
            circular_primes.add(p)
    return len(circular_primes)
Beispiel #9
0
def ans():
    # The insight is that n / phi(n) is minimized when n has a few, large prime
    # factors (n can't be prime, since prime numbers don't satisfy the
    # permutation criteria). Also, note that we don't actually have to compute
    # all of the numbers coprime with n to determine phi(n); instead we can use
    # the fact that n is a product of two primes to calculate phi(n) in
    # constant time.
    min_n = None
    min_value = None
    primes = Prime.gen_nums(10**4)
    combos = combinations(primes, 2)
    for one, two in list(combos):
        n = one * two
        if 10**7 <= n:
            continue
        num_coprimes = one * two - one - two + 1
        if sorted(str(n)) == sorted(str(num_coprimes)):
            value = n / num_coprimes
            if not min_value or value < min_value:
                min_n = n
                min_value = value
    return min_n
Beispiel #10
0
def ans():
    return sum(Prime.gen_nums(2000000))