我需要總和為 1000的三個正整數的每個組合。這是我的嘗試,但我不確定這是否正確,因為我無法驗證它。def getSum(): l = [] for x in range(1, 999): total = 1000-x for y in range(1, 999): total = total-y if total>0: l.append([x, y, total]) return lprint len(getSum())我得到 28776 種不同的組合。那是對的嗎?
查看完整描述