从10个数字中选出6个,选两次再相互组合,总共只有$\binom{10}{6}^2\cdot 6^2\cdot 2$约三百万种可能,因此暴力搜索即得结果$1217$。
import itertools
d=[0,1,2,3,4,5,6,7,8,9]
t=0
q={6:9,19:16,39:36,46:49,94:64}
for a in itertools.combinations(d,6):
for b in itertools.combinations(d,6):
p=dict.fromkeys([1,4,9,16,25,36,49,64,81],1)
for i in a:
for j in b:
k=q.get(i*10+j,i*10+j)
if k in p:
p[k]=0
k=q.get(j*10+i,j*10+i)
if k in p:
p[k]=0
if sum(p[k] for k in p)==0:
t+=1
print t/2
|