# python 3.x – Prime pair sets | Project Euler #60 | Need code optimization

I am on problem 60 of Project Euler and my code is too slow to find the required 5 numbers. I can find 4 numbers easily under a second but finding 5 is taking very long. Can you help me identify what may be causing the problem?

`funcs` are my local helper functions and the sieve algorithms is quite good. I don’t think its causing the bottleneck.

Problem prompt:

The primes 3, 7, 109, and 673, are quite remarkable. By taking any two primes and concatenating them in any order the result will always be prime. For example, taking 7 and 109, both 7109 and 1097 are prime. The sum of these four primes, 792, represents the lowest sum for a set of four primes with this property.

Find the lowest sum for a set of five primes for which any two primes concatenate to produce another prime.

``````#! /usr/bin/env python

from sympy import isprime
from funcs import sieve
from itertools import permutations

def concats_are_prime(l):
"""
Takes an iterable and checks if all possible number permutations are prime
"""
perms = ()
for i in permutations(l, 2):
perms.append(int(''.join(map(str, i))))
return all((isprime(i) for i in perms))

def p60():
candidates = {3}
for prime in sieve(10000000):