n 个连续数之和

sum(range(0, n+1))

This is not efficient and we can do the same using the below formula.

sum_n = n*(n+1)//2
 

おすすめ

転載: blog.csdn.net/weixin_43332715/article/details/121105071