def is_truncatable_prime(n): if not my_module.is_prime(n): return(False) for i in xrange(1, len(str(n))): if not my_module.is_prime(int(str(n)[:i])): return(False) if not my_module.is_prime(int(str(n)[i:])): return(False) return(True)
def get_distinct_prime_factors(n): prime_factors = [] divisors = my_module.get_proper_divisors(n) for i in divisors: if my_module.is_prime(i): prime_factors.append(i) return(prime_factors)
def consecutive_primes_from_quadratic(a, b): primes = 0 for i in xrange(0, 100000): if ((i ** 2) + (i * a) + b) > 1: if my_module.is_prime((i ** 2) + (i * a) + b): primes += 1 else: break return(primes)
def is_list_prime(primelist): for i in primelist: if not my_module.is_prime(i): return(False) return(True)
def generate_prime(floor, ceiling): primes = [] for i in xrange(floor, ceiling): if my_module.is_prime(i): primes.append(i) return primes
import my_module primesums = [] primesumslen = [] primes = my_module.generate_prime(2, 10000) for a in xrange(1, len(primes)): for b in xrange(1, len(primes)): if sum(primes[a:][:-b]) < 1000000: if my_module.is_prime(sum(primes[a:][:-b])): primesums.append(sum(primes[a:][:-b])) primesumslen.append(len(primes[a:][:-b])) print(primesums[primesumslen.index(max(primesumslen))])
def test_is_prime(self): self.assertFalse(my_module.is_prime(1)) self.assertTrue(my_module.is_prime(2)) self.assertTrue(my_module.is_prime(193)) self.assertFalse(my_module.is_prime(49))
import my_module for i in xrange(2, 5800): if i % 2 == 1: if not my_module.is_prime(i): if not my_module.is_goldback_composite(i): print(i)
import my_module import itertools permutations = itertools.permutations('1234567', 7) intpermutations = [int("".join(i)) for i in permutations] primes = [] for n in intpermutations: if my_module.is_prime(n): primes.append(n) print(max(primes))
families.append(family) return(families) def getfamilymembers(n): families = getfamilies(n) familymembers = [] for i in families: family = [] for x in range(1, 10): member = [] for digit in i: if digit == "*": member.append(str(x)) else: member.append(digit) family.append("".join(member)) familymembers.append(family) return(familymembers) primes = (my_module.generate_prime(10, 130000)) for i in primes: for family in getfamilymembers(str(i)): count = 0 for n in family: if my_module.is_prime(int(n)): count += 1 if count == 8: print(min(family)) sys.exit()
def is_circular_prime(n): if my_module.is_prime(n): rotations = my_module.get_rotations(n) if my_module.is_list_prime(rotations): return(True) return(False)