Python 10行代码速通
查看原帖
Python 10行代码速通
690474
antonsynonym楼主2024/7/25 18:11
current=[(0,)]
def message(k,p,depth=1):
    global current
    if p==1:return sum(k**i for i in current[-1])
    for tp in [()]+current.copy():
        current.append(tp+(depth,))
        p-=1
        if p==1:break
    return message(k,p,depth+1)
if __name__=='__main__':print(message(*tuple(int(i)for i in input().strip().split())))
2024/7/25 18:11
加载中...