def trunk_prime(n): if n == 2 or n == 3 or n == 5 or n == 7: return False if not is_prime(n): return False digs = [i for i in str(n)] for i in range(1, len(digs)): right = int("".join(digs[i:])) # print(right) left = int("".join(digs[:i])) if not is_prime(right) or not is_prime(left): return False return True
def sequece_length(a, b): n = 0 while True: numb = abs(quad(n, a, b)) if not is_prime(numb): return n n += 1
def _strong_harshad_numbers(n, digits_sum): for i in range(10): next_n = (10 * n) + i dig_sum_i = digits_sum + i if next_n <= LIMIT and next_n % (dig_sum_i) == 0: if is_prime((next_n / dig_sum_i)): rthp.update(_harshad_primes(next_n)) _strong_harshad_numbers(next_n, dig_sum_i)
def prime_sums(n): # this is the same as my coin sums code primes = [p for p in range(2, n) if is_prime(p)] ok_primes = [i for i in primes if i < (n + 1)] # print(ok_coins) sums = [0] * (n + 1) sums[0] = 1 for prime in ok_primes: for i in range(prime, n + 1): sums[i] += sums[abs(i - prime)] return sums[n]
def p046(): n = 3 prime_numbers = set() prime_numbers.add(2) while True: if is_prime(n): prime_numbers.add(n) else: for p in prime_numbers: if sqrt(((n - p) / 2)) == int(sqrt(((n - p) / 2))): break # break if it works with the conjecture else: return n n += 2
def spiral_prime_iterator(ratio_bound): ratio = 0.5 i = 0 addon = 2 adds = 0 no_primes = 0 total_nums = 0 while ratio > ratio_bound: if adds > 0 and adds % 4 == 0: addon += 2 i += addon adds += 1 total_nums += 1 if is_prime(i + 1): no_primes += 1 ratio = truediv(no_primes, total_nums) return addon + 1
def p049(): four_dig_primes = [i for i in range(1000, 10000) if is_prime(i)] num_4dig_primes = len(four_dig_primes) prime_perms = defaultdict(list) for prime in four_dig_primes: sorted_digs = tuple(sorted(digits_list(prime))) prime_perms[sorted_digs].append(prime) topop = [k for k, v in prime_perms.items() if len(v) < 3] for toop in topop: prime_perms.pop(toop) validsets = [] for k, v in prime_perms.items(): for combo in combinations(v, 3): if combo[1] - combo[0] == combo[2] - combo[1]: validsets.append(combo) return int("".join(str(n) for n in validsets[1]))
def check_pair(p1, p2): if is_prime(concat_numbers(p1, p2)) and is_prime(concat_numbers(p2, p1)): return True else: return False
def _harshad_primes(n): return set(a for a in (n * 10 + i for i in range(1, 10)) if is_prime(a) and a < LIMIT)
def is_circ_prime(n): digist = [int(j) for j in digits_list(n)] return all((is_prime(int_from_digits(i)) for i in rotations_gen(digist)))
def p026(): primes_lt1000 = [i for i in range(1, 1000) if is_prime(i)] cycles = [num_cycles(p) for p in primes_lt1000] return primes_lt1000[cycles.index(max(cycles))]
def test_is_prime(): """ """ assert all(is_prime(n) for n in p_lt200)