题解 | #百钱买百鸡问题#
尼科彻斯定理
http://www.nowcoder.com/practice/dbace3a5b3c4480e86ee3277f3fe1e85
#9命,调了好久终于把运行时间调到规定内了🤣
def nk(count,n,m): if sum(count) == n and len(count) == m: print(str(count).replace("[","").replace(",", "+").replace("]","").replace(" ","")) return True while True: try: m = int(input()) n = m * m * m #n是m的立方 count = [] flag = 0 i = 0 while flag ==0: for j in range(i,i+2*m+1,2):#遍历j往后的m个奇数,若总和为n则输出 count.append(j) if (nk(count,n,m)): flag = 1 i += 1 count = [] except: break