def check(a, b): # print a, b if (a,b) in cache: return cache[(a,b)] else: p1 = int(str(a)+str(b)) p2 = int(str(b)+str(a)) retval =(p1 in primes_s and p2 in primes_s) or (c_prime.is_prime(p1) and c_prime.is_prime(p2)) cache[(a,b)] = retval return retval
def solve(length): odd = set(("1","3","5","7","9")) retval = None for digits in permutations(map(str, range(1,length+1)), length): if digits[-1] in odd: num = int("".join(digits)) if c_prime.is_prime(num): retval = num return retval