def run(): thres = int(10**10) for _n, p in enumerate(primelist(1000000)): n = _n + 1 if n % 2 == 0: continue elif 2 * n * p > thres: return n
def run(): n = 1000000 primes = primelist(n) i, result = 0, 1 while result * primes[i] < n: result *= primes[i] i += 1 return result
def run(): N = 1000000 primes = primelist(N) circPrimes = [] for i in primes: if all(is_prime(x) for x in CircPerms(i)): circPrimes.append(i) return len(circPrimes)
def run(): primes = primelist(10000000) Asmall, _ = sequence_slow(80, primes) Abig = sequence_fast(500500-80, Asmall, primes) out = 1 for i, a in enumerate(Abig): out = (out*primes[i]**(2**a-1)) % 500500507 return out
def primeFactors(x): # returns the prime factors of x. primes = primelist(x + 1) factors = [] while x > 1: for p in primes: if x % p == 0: factors.append(p) x = x // p break return factors
def run(): primes = primelist(1000000)[4:] truncPrimes = [] for p in primes: if all(is_prime(x) for x in leftTrunc(p)) and all(is_prime(x) for x in rightTrunc(p)): truncPrimes.append(p) if len(truncPrimes) == 11: break return sum(truncPrimes)
def run(): p_max = 1000000 a_max = int(sqrt(p_max - 1)) primes = primelist(p_max) ans = {} for a in range(1, a_max): p = 3 * a**2 + 3 * a + 1 if p in primes: ans[p] = a #for k, v in ans.items(): print(f'p = {k}, n = {v}') return len(ans)
def run(N=10000000): primes = primelist(N // 2) Sum = 0 for i, p in enumerate(primes): if p * primes[i + 1] > N: break for q in primes[i + 1:]: if p * q > N: break M = largest_integer_divisible_by_2_primes(p, q, N) #print(p, q, M) Sum += M return Sum
def run(): target = 8 primes = primelist(1000000) found = False targetExclusionList = '' targetRepDigs = '' for n in range(2, 8): primeSet = list((str(x)) for x in primes if numDigits(x) == n) for ex in exclusionList(n): currentCount = Counter() for p in primeSet: repDigs = '' changeDigs = '' for i, k in enumerate(ex): if k == '1': #exclude changeDigs += p[i] else: repDigs += p[i] if changeDigs.count(changeDigs[0]) == len( changeDigs): #if all changing digits are equal currentCount[repDigs] += 1 if currentCount[repDigs] == target: found = True targetExclusionList = ex targetRepDigs = repDigs if found: break if found: break if found: #go through array again and print answers ans = [] for p in primeSet: repDigs = '' changeDigs = '' for i, k in enumerate(targetExclusionList): if k == '1': #exclude changeDigs += p[i] else: repDigs += p[i] if changeDigs.count(changeDigs[0]) == len( changeDigs): #if all changing digits are equal if repDigs == targetRepDigs: ans.append(p) break return min(int(x) for x in ans)
def run(): primes = [x for x in primelist(10000) if numDigits(x) == 4] for p in primes: primePerms = list(set(sorted(x for x in Perms(p) if is_prime(x)))) while len(primePerms) >= 3: diff = primePerms[1] - primePerms[0] for n in primePerms[2:]: if (n - primePerms[0]) / diff == 2: out = ''.join([str(x) for x in primePerms[0:3]]) if len(out) == 12: return int(out) primePerms.remove(primePerms[1]) return -1
def run(): N = 50000000 primes = primelist(N) count = 2 for p in primes[1:]: if (p+1)%4 == 0: # print(p) count += 1 if (2*p+2)%4 == 0 and 4*p < N: # print(4*p) count += 1 if (4*p+4)%4 == 0 and 16*p < N: # print(16*p) count += 1 return count
def run(): primes = primelist(10000) squares = list(x * x for x in range(1, 100)) for i in range(7, 10000, 2): if i not in primes: thisNumisGood = False for p in (x for x in primes if x <= i - 1): if ((i - p) / 2).is_integer() and int((i - p) / 2) in squares: thisNumisGood = True if not thisNumisGood: return i break return -1
def run(): primes = primelist(limit) aMax, bMax, nMax = 0, 0, 0 for a in range(-Range, Range): # b must be prime for the case n=0 for b in (b_ for b_ in primes if b_ < Range): f = lambda x: x**2 + a * x + b n = 0 while f(n) in primes: n += 1 if n > nMax: aMax, bMax, nMax = a, b, n return aMax * bMax
def run(): primes = primelist(100) for n in range(2, 100): num_ways = ways(n, len(primes) - 1, primes) if num_ways > 5000: return n
# -*- coding: utf-8 -*- """ Solution to Project Euler problem 110 Author: Jaime Liew https://github.com/jaimeliew1/Project_Euler_Solutions """ from EulerFunctions import primelist from collections import Counter from math import sqrt, ceil N_max = int(5e8) primes = primelist(N_max) def product(lst): out = 1 for x in lst: out *= x return out def primeFactor(n): primefactors = Counter() while n > 1: for p in primes: if n%p == 0: n = n//p primefactors[p] += 1 return dict(primefactors)
def run(): N = 600851475143 return max(p for p in primelist(int(N**0.5)) if N % p == 0)
# -*- coding: utf-8 -*- """ Solution to Project Euler problem X Author: Jaime Liew https://github.com/jaimeliew1/Project_Euler_Solutions """ from EulerFunctions import primelist primes = primelist(100000) def npf(n): #number of prime factors num = 0 for p in (x for x in primes if x <= n / 2): if n % p == 0: num += 1 if num == 0: return 1 else: return num def run(): notFound = True i = 134000 # 2*3*5*7 while notFound: if i % 1000 == 0: #print(i)
def run(): N = 2000000 primes = primelist(N) return sum(primes) return -1