def main(top=1000000): prime_found = None # Generate a list with cumalitive sum cum_sum_primes = [0] cum_sum = 0 for p in primes_erat(): cum_sum += p cum_sum_primes.append(cum_sum) if cum_sum > top: break num_primes = len(cum_sum_primes) num_terms = num_primes while True: for offset in range(0, 10): if offset + num_terms >= num_primes: break sum_of_primes = cum_sum_primes[offset + num_terms] - cum_sum_primes[offset] if sum_of_primes < top and is_prime(sum_of_primes): prime_found = sum_of_primes break if prime_found: break num_terms -= 1 return prime_found
def find_count(n): sump = 0 i = n prime = 0 while sump + primes[i + 1] < 10**6: sump += primes[i] i += 1 if is_prime(sump): prime = sump return prime
def f(n): """ #11914460 >>> sum(f(15 * (10 ** 7))) 676333270 >>> sum(f(2000000)) 1242490 >>> sum(f(100)) 10 """ ps = list(primes(5000)) steps = list(get_steps(ps, n)) for i in steps: if i >= n: break sq_i = i * i if ( i < n and all(map(lambda x: is_prime(sq_i + x), ADD_List)) and all(map(lambda x: not is_prime(sq_i + x), [11, 17, 19, 21, 23])) ): yield i
def try_formula(a, b): """ >>> try_formula(1, 41) 40 >>> try_formula(-79, 1601) 80 """ n = 0 while True: x = (n**2) + (a * n) + b if not is_prime(x): break n += 1 return n
def prime_proof(x): sx = str(x) n = len(sx) for i in range(n): if i == 0: Q = (1, 2, 3, 4, 5, 6, 7, 8, 9) else: Q = (0, 1, 2, 3, 4, 5, 6, 7, 8, 9) for q in Q: sy = list(sx) sy[i] = str(q) y = int(''.join(sy)) if eulertools.is_prime(y): return False return True
def main(max_prime=1000000): prime_list = set( p for p in itertools.takewhile(lambda x: x < max_prime, primes_erat())) count = 0 for n in prime_list: is_circular = True for x in rotations(str(n)): x = int(x) if x == n: continue if x < max_prime and not x in prime_list: is_circular = False break elif x >= max_prime and not is_prime(x): is_circular = False break if is_circular: count += 1 return count
#_______Description_____ #https://projecteuler.net/problem=51 #By replacing the 1st digit of the 2-digit number *3, it turns out that six of the nine possible values: 13, 23, 43, 53, 73, and 83, are all prime. #By replacing the 3rd and 4th digits of 56**3 with the same digit, this 5-digit number is the first example having seven primes among the ten generated numbers, yielding the family: 56003, 56113, 56333, 56443, 56663, 56773, and 56993. Consequently 56003, being the first member of this family, is the smallest prime with this property. #Find the smallest prime which, by replacing part of the number (not necessarily adjacent digits) with the same digit, is part of an eight prime value family. ##_______end_description_____: from eulertools import Sieve, is_prime primes_set = set(Sieve(999999)) primes_reduce = set() for i in primes_set: if i > 100000: digits = [n for n in str(i)] for n in digits: if digits.count(n) == 3 and n != digits[5] and any( (n == '0', n == '1', n == '2')): primes_reduce.add(i) for i in primes_reduce: digits = str(i) count = 0 for n in digits: if digits.count(n) == 3: repeating = n break for d in range(0, 10): new_prime = int(digits.replace(repeating, str(d), 3)) if is_prime(new_prime) and new_prime > 100000: count += 1 if count == 8: print(i) break
#_______Description_____ #https://projecteuler.net/problem=41 #We shall say that an n-digit number is pandigital if it makes use of all the digits 1 to n exactly once. For example, 2143 is a 4-digit pandigital and is also prime. #What is the largest n-digit pandigital prime that exists? ##_______end_description_____: #only 4 and 7 digit pandigital numbers can be prime because otherwise sum of all digit is divisble by 3 meaning whole number #is divisible by 3. That's why limit is largest pandigital 7-digit number. from eulertools import is_prime, is_pandigital for n in range(7654321, 1, -2): # looping down, decrementing by 2 if is_pandigital(n): if is_prime(n): print(n) break