def findSums(N, n_0, count_self=True): if count_self and PC.PrimeCheck(N) and N <= n_0: yield (1) for n in PC.primes(2, n_0 + 1): dn = N - n if dn > 1: yield (sum([s for s in findSums(dn, min([dn, n]))]))
def oddComposite(): x = 9 yield(x) while True: x += 2 if primeCheckII.PrimeCheck(x): continue yield(x)
def _rotPrime(str_p): new_str_p = str_p[1:] + str_p[0] p_list = [int(str_p)] while new_str_p != str_p: if not primeCheckII.PrimeCheck(int(new_str_p)): return (False) p_list.append(int(new_str_p)) new_str_p = new_str_p[1:] + new_str_p[0] return (p_list)
def findSpecialPrimes(): checked_list = [] for prime in primeCheckII.primes(1000,10000): #print(prime) for p in permutation([x for x in range(len(str(prime)))],len(str(prime))): s = [str(prime)[x] for x in p] next_prime = int("".join(s)) if len(str(next_prime)) < PRIME_LENGTH or next_prime <= prime: continue if primeCheckII.PrimeCheck(next_prime): d_prime = next_prime - prime last_prime = next_prime + d_prime if len(str(last_prime)) != PRIME_LENGTH: continue if primeCheckII.PrimeCheck(last_prime): if Counter([s for s in str(last_prime)]) == Counter(s): if prime not in checked_list: checked_list.append(prime) yield([prime,next_prime,last_prime])
def _truncPrimeRight(str_p, trunc_primes): cut_right = str_p[:-1] if cut_right == '1' or cut_right == '9': return (False) if int(cut_right) not in trunc_primes: while len(cut_right) > 0: if not primeCheckII.PrimeCheck(int(cut_right)): return (False) cut_right = cut_right[:-1] return (True)
def _truncPrimeLeft(str_p, trunc_primes): cut_left = str_p[1:] if cut_left == '1' or cut_left == '9': return (False) if int(cut_left) not in trunc_primes: while len(cut_left) > 0: if not primeCheckII.PrimeCheck(int(cut_left)): return (False) cut_left = cut_left[1:] return (True)
def findPanPrime(): for d in range(8, 1, -1): digits = [x for x in range(1, d)] digits.reverse() if sum(digits) % 3 == 0: continue for p in permutation(digits, len(digits)): if p[-1] not in BAD_END_NUMS: n = int("".join([str(x) for x in p])) if primeCheckII.PrimeCheck(n): return (n)
def buildNum(str_x, trunc_primes): if len(str_x) == 0: for num in START_NUMS: for new_str_x in buildNum(num, trunc_primes): yield (new_str_x) elif len(str_x) < MAX_DIGITS: for num in GOOD_NUMS: if str_x[0] in GOOD_LEFT_NUMS: new_nums = [str_x + num] elif str_x[0] in BAD_END_NUMS and len(str_x) > 1: new_nums = [num + str_x] elif str_x[-1] in BAD_END_NUMS and len(str_x) > 1: new_nums = [str_x + num] else: new_nums = [num + str_x, str_x + num] for new_num in new_nums: if primeCheckII.PrimeCheck(int(new_num)): if _truncPrimeLeft(new_num, trunc_primes) and _truncPrimeRight( new_num, trunc_primes): yield (new_num) for new_str_x in buildNum(new_num, trunc_primes): yield (new_str_x)
break prime_list.append(p) min_run_len = 22 run_len = min_run_len prime_sum = 0 for i in range(len(prime_list)): if prime_sum + prime_list[i] < MAX_p: prime_sum += prime_list[i] else: run_len = i + 1 i = 0 run = True run_list = [] prime_sum = 0 while run: run_list = prime_list[i:i + run_len] prime_sum = sum(run_list) if prime_sum > MAX_p: i = 0 run_len -= 1 elif primeCheckII.PrimeCheck(prime_sum): run = False else: i += 1 print(i, run_len) print(prime_sum, len(run_list), run_list)
def combinePrimes(a,b): return(primeCheckII.PrimeCheck(int(str(a)+str(b))) and primeCheckII.PrimeCheck(int(str(b)+str(a))))
def countFractions(N): s = N - 1 if not primeCheckII.PrimeCheck(N): D = findDivisors(N, False, False) s -= sum([countFractions(d) for d in D]) return (s)
TR: previousBR + size-1 TL: TR + size-1 BL: TL + size-1 BR: BL + size-1 then increase size by 2 """ from math import sqrt import primeCheckII size = 1 ratio = 1.0 check_list = [] TR = TL = BL = BR = 1 prime_count = 0 while ratio >= 0.1: size += 2 TR = BR + size - 1 TL = TR + size - 1 BL = TL + size - 1 BR = BL + size - 1 check_list = [TR, TL, BL, BR] total = 2 * (size - 1) + 1 for x in check_list: if primeCheckII.PrimeCheck(x): prime_count += 1 ratio = prime_count / total print(ratio) print(prime_count, total, ratio, size)