容易看出乘数和被乘数的位数只能是1,4或2,3,相乘后都必须得到四位数,暴力搜索即得结果$45228$。
import itertools
panSet=set([])
for i,j in itertools.chain(itertools.product(range(1,10),range(1000,10000)),itertools.product(range(10,100),range(100,1000))):
k=i*j
s=str(i)+str(j)+str(k)
if len(set(s))==len(s)==9 and "0" not in s and k not in panSet:
panSet.add(k)
print sum(panSet)
|