#!/usr/bin/env python3 from functools import lru_cache from math import isqrt N=112 @lru_cache(None) def possible(T): B=set(T) S={x+y for x in B for y in B} if 113 in S:return False D=S-{x*y for x in B for y in B} if not D:return True def pairs(s): return [(u,s//u) for u in range(1,isqrt(s)+1) if s%u==0 and s//u<=N and 113-u not in B and 113-s//u not in B and u+s//u!=113] s=min(D,key=lambda s:len(pairs(s))) return any(possible(tuple(sorted(B|{u,v}))) for u,v in pairs(s)) print(possible((1,2,3,5,7))) print(possible.cache_info()) A=set(range(1,13))|{16,113}|set(range(13,110,2)) S={x+y for x in A for y in A};P={x*y for x in A for y in A} print(len(A),max(A),sorted(S-P)) print(S==set(range(2,223,2))|{226}|set(range(3,126,2))|{129})