| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 4588 人关注过本帖
标题:关于鬼谷子问徒
只看楼主 加入收藏
simpley
Rank: 1
等 级:新手上路
帖 子:262
专家分:0
注 册:2005-2-23
收藏
得分:0 
分析出和是11,17,23,27,29,35,37,47,51,53。可以继续推理:
任何一个奇数只要能写成2^N+K(N>1,K为质数),那么就不存在另外另外一个奇数2^M+G(M>1,G为质数),使得2^N*K=2^M*G.

所以孙膑只要掌握了一个2^N*K,他就可以说:本来我不知道,现在听你一说就知道了."

而庞涓要知道这两个数,那么它的和只能惟一地可以写成2^N+K(N>1,K为质数),这样剩下的数就是17 29 41 53
从这里往下可以进行编程.不过手算也很快了.

myQQ::445750010
2008-06-14 14:47
daoyunmaihua
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2020-4-17
收藏
得分:0 
这个问题只有唯一解。
程序代码:
def sum_split(Sum, low, high):
    ans = []
    for a in range(low, high+1):
        b = Sum - a
        if b <= a:
            break
        if b <= high:
            ans.append((a,b))
    return ans


def porduct_split(Product, low, high):
    ans = []
    for a in range(low, high+1):
        b = Product // a
        if b <= a:
            break
        if Product%a == 0 and b <= high:
            ans.append((a,b))
    return ans


def 由和可以直接得ab(A):
    """
    和为A,是否能直接推出a,b
    若能直接推出a,b返回True
    若不能直接推出a,b则返回False
    """
    sp = sum_split(A, 2, 99)
    return len(sp) == 1


def 由积可以直接得ab(B):
    """
    乘积为B,是否能直接推出a,b
    若能直接推出a,b返回True
    若不能直接推出a,b则返回False
    """
    sp = sum_split(A, 2, 99)
    return len(sp) == 1


def F(A):
    """
    F(A)==1
    验证A是否符合到庞统的第二句话,但是我肯定你(指孙膑)也不知道这两个数是什么
    如果是True将返回所有可能的B;如果False,则第二个参数返回的是[]
    """
    # if not 由和可以直接得ab(A):
    #     return False
    sp = sum_split(A, 2, 99)
    possible_B = []
    for this_case in sp:
        a, b = this_case[0], this_case[1]
        pp = porduct_split(a*b, 2, 99)
        if 1 == len(pp): # 分解方式唯一
            return False, []
        else:
            possible_B.append(a*b)
    return True, possible_B # 每种分拆情况都不唯一


def G(B):
    """
    B(B)==1
    验证B是否符合到孙膑的第二句话,但是听你这么一说,我现在能够确定这两个数字了
    及返回所有F(A)为True(1)的A的列表
    """
    # if not 由和可以直接得ab(A):
    #     return False
    pp = porduct_split(B, 2, 99)
    possible_A = []
    for this_case in pp:
        a, b = this_case[0], this_case[1]
        A = a + b
        FA, Bs = F(A)
        if FA:
            possible_A.append(A)
    return len(possible_A) == 1, possible_A


def main():
    possible_A1 = []
    for i in range(2+3,98+99+1):
        if not 由和可以直接得ab(i):
            possible_A1.append(i)
    print("possible_A1 =", possible_A1, "个数:", len(possible_A1))
    possible_A2 = []
    possbile_A2_dict = {}
    for A in possible_A1:
        is_possible, possible_B = F(A)
        if is_possible:
            possible_A2.append(A)
            possbile_A2_dict[A] = possible_B
    print("possible_A2 =", possible_A2, "个数:", len(possible_A2))
    # 针对每种可能的A,给出每种情况下,B可能的取值。
    print("针对每种可能的A,给出每种情况下,B可能的取值。")
    for A, Bs in possbile_A2_dict.items():
        print("A = {} 可能的B = {}".format(A, Bs))
    # 所有可能的B的可能集的并集
    B_candidates = set()
    for Bs in possbile_A2_dict.values():
        for B in Bs:
            B_candidates.add(B)
    print("B候选集大小", len(B_candidates))
    possible_B4 = []
    possible_B4_dict = {}
    for B in B_candidates:
        possible, possible_A = G(B)
        if possible:
            possible_B4.append(B)
            possible_B4_dict[B] = possible_A[0]
    possible_B4.sort()
    print("Possible_B4 = ",possible_B4, "个数 =", len(possible_B4))
    pk = 0
    for B, A in possible_B4_dict.items():
        pk += 1
        print("(B = {: >3},A = {: >2})".format(B,A), end="\t")
        if pk == 6:
            print()
            pk = 0
    # 根据最后的庞统的话缩小范围
    possible_B4_set = set(possible_B4)
    possible_A5_set = set()
    possible_AB_set = set()
    for A, possible_B in possbile_A2_dict.items():
        remain_B_set = set(possible_B) & possible_B4_set
        print("A = {} 剩余的B = {}".format(A, remain_B_set))
        if len(remain_B_set) == 1:
            possible_A5_set.add(A)
            B = list(remain_B_set)[0]
            possible_AB_set.add((A, B))
    print("目前为止(A,B)可能的解是:")
    print(possible_AB_set)


if __name__ == "__main__":
    main()
    #F(11)

鬼谷子问徒分析求解.pdf (366.15 KB)
2020-04-17 14:04
快速回复:关于鬼谷子问徒
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016509 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved