Ejemplo n.º 1
0
def main():
    for prime in prime_sieve_lazy():
        if prime < 10**4:  # rewind to the first 5-digit prime
            continue

        s = str(prime)

        # we're searching from low to high
        for digit in "012":
            count = s.count(digit)

            # Some observaions:
            #  * count has to be a multiple of 3, otherwise some of the new
            #    primes will be divisible by 3.
            #  * the rightmost digit can't be replaced (it could only be "1")
            if count and not count % 3 and not digit == "1" == s[-1]:
                cnt = 1

                for i in range(int(digit) + 1, 10):
                    if i - cnt > 2:
                        break

                    if is_prime(int(s.replace(digit, str(i), count))):
                        cnt += 1
                        if cnt == 8:
                            return prime
Ejemplo n.º 2
0
def main():
    factors = []

    for prime in prime_sieve_lazy():
        if pow(10, 10**9, 9 * prime) == 1:  # R(k) = (10**k - 1) // 9
            factors.append(prime)
            if len(factors) == 40:
                return sum(factors)
Ejemplo n.º 3
0
def main():
    factors = []

    for prime in prime_sieve_lazy():
        if pow(10, 10**9, 9*prime) == 1:  # R(k) = (10**k - 1) // 9
            factors.append(prime)
            if len(factors) == 40:
                return sum(factors)
Ejemplo n.º 4
0
def main():
    lim = 1000000
    res = 1

    for prime in prime_sieve_lazy():
        if res * prime > lim:
            break
        res *= prime

    return res
Ejemplo n.º 5
0
def main():
    res = cnt = 0

    for p in prime_sieve_lazy():
        if is_truncatable(p):
            res += p
            cnt += 1

            if cnt == 11:
                return res
Ejemplo n.º 6
0
def main():
    lim = 1000000
    res = 1

    for prime in prime_sieve_lazy():
        if res*prime > lim:
            break
        res *= prime

    return res
Ejemplo n.º 7
0
def main():
    nways = 5000

    for num in count(10):
        ways = [0]*(num+1)
        ways[0] = 1

        for p in prime_sieve_lazy():
            if p > num:
                break

            for i in range(p, num+1):
                ways[i] += ways[i-p]

        if ways[num] > nways:
            return num
Ejemplo n.º 8
0
def main():
    nways = 5000

    for num in count(10):
        ways = [0] * (num + 1)
        ways[0] = 1

        for p in prime_sieve_lazy():
            if p > num:
                break

            for i in range(p, num + 1):
                ways[i] += ways[i - p]

        if ways[num] > nways:
            return num
Ejemplo n.º 9
0
def main():
    lim = 1_000_000
    primes = prime_sieve_lazy()
    next(primes)
    next(primes)
    res = 0

    # p1 + d * k == 0 (mod p2).
    for p1, p2 in pairwise(primes):
        if p1 > lim:
            break
        d = 10**(ceil(log10(p1)))
        dinv = pow(d, p2 - 2, p2)
        k = ((p2 - p1) * dinv) % p2
        res += p1 + d * k

    return res
Ejemplo n.º 10
0
def main():
    lim = 1_000_000
    primes = prime_sieve_lazy()
    next(primes)
    next(primes)
    res = 0

    # p1 + d * k == 0 (mod p2).
    for p1, p2 in pairwise(primes):
        if p1 > lim:
            break
        d = 10**(ceil(log10(p1)))
        dinv = pow(d, p2 - 2, p2)
        k = ((p2 - p1) * dinv) % p2
        res += p1 + d * k

    return res
Ejemplo n.º 11
0
def main():
    for n, p in islice(enumerate(prime_sieve_lazy(), 1), 0, None, 2):
        if 2*p*n > 10**10:
            return n
Ejemplo n.º 12
0
def main():
    for count, prime in enumerate(prime_sieve_lazy(), 1):
        if count == 10001:
            return prime
Ejemplo n.º 13
0
def main():
    for n, p in islice(enumerate(prime_sieve_lazy(), 1), 0, None, 2):
        if 2 * p * n > 10**10:
            return n