def count(arrs, depth): res = 0 for arr in arrs: if arr[0] == 0: continue if isPrime(prod(arr)): res += prod(arr) return res // factorial(depth)
def M(n, digit): hoeveel = 1 array = n * [digit] while True: nrs = permute(array, digit, hoeveel) for nr in nrs: if nr[0] == 0: continue if isPrime(prod(nr)): return nrs, hoeveel hoeveel += 1
def func(): idx = 0 m = len(primes) while True: p = primes[idx] cdx = idx + 1 while cdx < m: temp = [p] a1 = digitsum(p) % 3 bdx = cdx while bdx < m: new_p = primes[bdx] if ((digitsum(new_p)) % 3) != a1: bdx += 1 continue flag = True for pr in temp: front = int(str(pr) + str(new_p)) back = int(str(new_p) + str(pr)) if not (isPrime(front) and isPrime(back)): flag = False break if flag: temp.append(new_p) if len(temp) >= 5: print "FOUND ONE" print temp print "Result = " + str(sum(temp)) return bdx += 1 if len(temp) > 1: cdx = d[temp[1]] + 1 else: break idx += 1
# -*- coding: utf-8 -*- from eulerTools import isPrime from datetime import datetime startTime = datetime.now() totalcount = 0 truecount = 0 length = 1 start = 1 totalcount += 1 increment = 2 while True: totalcount += 4 length += 2 for i in range(4): start += increment if i == 3: continue if isPrime(start): truecount += 1 increment += 2 if truecount / float(totalcount) < 0.1: break print length print datetime.now() - startTime #time 12s
# -*- coding: utf-8 -*- from eulerTools import isPrime from datetime import datetime startTime = datetime.now() #more prime factors => phi(n) is minimal hoog = 1000000 r = 1 n = 2 while r < hoog: if isPrime(n): r *= n n += 1 r /= (n - 1) print "res = " + str(r) print(datetime.now() - startTime) #5ms
from datetime import datetime startTime = datetime.now() from timeit import default_timer as timer start = timer() cutoff = int(4e6) highest_prime_idx = int(ceil(log(cutoff, 3))) cutoff = cutoff*2 - 1 primes = [2] list_l = 1 k = 3 while list_l < highest_prime_idx: if isPrime(k): primes.append(k) list_l += 1 k += 2 import heapq import itertools #code taken from Python heapq documentation page pq = [] # list of entries arranged in a heap entry_finder = {} # mapping of tasks to entries REMOVED = '<removed-task>' # placeholder for a removed task counter = itertools.count() # unique sequence count def add_task(task, priority=0): 'Add a new task or update the priority of an existing task' if task in entry_finder:
def prime(n): if n > max_prime: return isPrime(n) return n in primes