原文:http://bbs.chinaunix.net/thread-4191271-1-1.html
def N2S(n): x = int(n / 2) + 1 + 1 s = [0] r = [] for i in range(1, x): s.append(s[-1] + i) for i in range(1, x): k = n + s[i - 1] for j in range(i + 1, x): if s[j] < k: continue if s[j] == k: r.append(range(i, j + 1)) break for i in r: print(list(i)) N2S(15)