驗證尼科徹斯定理(leetcode)

 驗證尼科徹斯定理,即:任何一個整數m的立方都可以寫成m個連續奇數之和。

例如:
1^3=1
2^3=3+5
3^3=7+9+11
4^3=13+15+17+19
輸入: 輸入一個int整數
輸出: 輸出分解後的string
Input: 6
Input: 31+33+35+37+39+41

while True:
    try:
        number = int(input())
        multi = number ** 2
        result = [str(i) for i in range(multi - number + 1, multi + number, 2)]
        print('+'.join(result))
    except Exception:
        break
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章