#!/usr/bin/env python3 import time,math,functools N=112;F={} for s in range(2,2*N+1): F[s]=[(u,s//u) for u in range(1,min(N,math.isqrt(s))+1) if s%u==0 and s//u<=N] t=time.time();vis=set();cnt=0;depth=0 def search(T): global cnt,depth if T in vis:return False vis.add(T);cnt+=1;depth=max(depth,len(T)) S={a+b for a in T for b in T};P={a*b for a in T for b in T} if S<=P:print('FOUND',T);return True D=S-P; ifopts=[] for s in D: opts=[(u,v) for u,v in F[s] if not ((113-u in T and u not in T) or (113-v in T and v not in T) or (u+v==113))] if not opts:return False ifopts.append((len(opts),s,opts)) _,s,opts=min(ifopts) for u,v in opts: if search(tuple(sorted(set(T)|{u,v}))):return True return False print('result',search((1,2,3,5,7)),'cnt',cnt,'depth',depth,'secs',round(time.time()-t,2))