#给可能空间赋值 for i in range(N,M): for j in range(i+1,M+1): probably_space_begin.append([(i,j),he(i,j),ji(i,j)]) probably_he.append(he(i,j))
#第一句话 #庞不能确定 ——> 和有两种以上分解方式 probably_space_1 = [i for i in probably_space_begin if probably_he.count(i[1]) >= 2] #庞说孙也不知道 ——> 和对应的分解的积的结果有两种以上 #先排除积空间中的独立值 probably_ji = [i[2] for i in probably_space_1] probably_space_alone = [i for i in probably_space_1 if probably_ji.count(i[2]) == 1 ] probably_space_2 = [i for i in probably_space_1 if i not in probably_space_alone] #排除积在probably_space_alone中的因子之和的情况 impossible_he = {i[1] for i in probably_space_alone} probably_space_3 = [i for i in probably_space_2 if i[1] not in impossible_he]
#第二句 #孙知道了——>在probably_space_3中确定积即可得到唯一答案 probably_ji = [i[2] for i in probably_space_3] probably_space_4 = [i for i in probably_space_3 if probably_ji.count(i[2]) == 1]
#第三句 #庞也知道了——>在probably_space_4中确定和即可得到唯一答案 probably_he = [i[1] for i in probably_space_4] probably_space_5 = [i for i in probably_space_4 if probably_he.count(i[1]) == 1]
#输出 if len(probably_space_5) == 1: print("两数分别为:",probably_space_5[0][0])