题解 | #尼科彻斯定理#

尼科彻斯定理

https://www.nowcoder.com/practice/dbace3a5b3c4480e86ee3277f3fe1e85

# 利用尼科彻斯定理的公式,n^3=(n^2-n+1)+(n^2-n+3)+...+(n^2-n+2n-1)
def Nicomachus(n):
    lst = []
    for i in range(1, 2*n, 2):
        j = n**2 - n + i
        lst.append(j)
    print(*lst, sep='+')

Nicomachus(int(input()))

# 直接看出来首尾数字的范围
# 4^3 = (4x3)13+15+17+19(4x5)
# 5^3 = (5x4)21+23+25+27+29(5x6)
while True:
    try:
        m = int(input())
        l = [i for i in range(m*(m-1)+1,m*(m+1)) if i%2 !=0]
        print('+'.join(map(str,l)))
    except:
        break

全部评论

相关推荐

我的offer在哪里...:从去年看到现在,飞升哥就是榜样
我的求职进度条
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务