def main(): primes = [2, 3] consecutives = [] number_of_consecutives = 4 index = 3 while len(consecutives) < number_of_consecutives: index += 1 if is_prime(index): primes.append(index) consecutives = [] continue prime_factors = set() factored = index for prime in primes: while factored % prime == 0 and factored and len( prime_factors) < number_of_consecutives + 1: prime_factors.add(prime) factored /= prime if not factored or len(prime_factors) > number_of_consecutives - 1: break if len(prime_factors) == number_of_consecutives: consecutives.append(index) else: consecutives = [] print consecutives
def main(): primes = [2, 3] consecutives = [] number_of_consecutives = 4 index = 3 while len(consecutives) < number_of_consecutives: index += 1 if is_prime(index): primes.append(index) consecutives = [] continue prime_factors = set() factored = index for prime in primes: while factored % prime == 0 and factored and len(prime_factors) < number_of_consecutives + 1: prime_factors.add(prime) factored /= prime if not factored or len(prime_factors) > number_of_consecutives - 1: break if len(prime_factors) == number_of_consecutives: consecutives.append(index) else: consecutives = [] print consecutives
def is_truncatable_prime(num): for i in ['0', '4', '6', '8']: if i in str(num): return False for i in ['2', '5']: if i in str(num)[1:]: return False if not is_prime(num): return False for idx in range(len(str(num)) - 1): if not is_prime(int(str(num)[idx+1:])): return False for idx in range(len(str(num)) - 1): if not is_prime(int(str(num)[0:-1*idx-1])): return False return True
def is_truncatable_prime(num): for i in ['0', '4', '6', '8']: if i in str(num): return False for i in ['2', '5']: if i in str(num)[1:]: return False if not is_prime(num): return False for idx in range(len(str(num)) - 1): if not is_prime(int(str(num)[idx + 1:])): return False for idx in range(len(str(num)) - 1): if not is_prime(int(str(num)[0:-1 * idx - 1])): return False return True
def main(): primes = [i for i in range(1000, 10000) if is_prime(i)] primes_set = set(primes) found_lists = [] while len(found_lists) < 2: first_prime = primes[0] primes.pop(0) for p in primes: prime_list = [first_prime] diff = p - first_prime if p + diff in primes_set: prime_list += [p, p + diff] if is_list_of_permutations(prime_list): found_lists.append(prime_list) print "".join([str(i) for i in found_lists[1]])
def main(): primes = set() index = 1 found_composite = 0 while not found_composite: index += 2 if is_prime(index): primes.add(index) continue correct_proposition = False for prime in primes: square = (index - prime) / 2.0 if int(square) == square and int(sqrt(square)) == sqrt(square): correct_proposition = True if not correct_proposition: found_composite = index print found_composite