5行Python3代码带你解决C++初学者很难做到的洛谷P1009 阶乘之和(亲测有效)

5行Python3代码带你解决C++初学者很难做到的洛谷P1009 阶乘之和(亲测有效)

洛谷P1009 阶乘之和网址(需登录才可提交评测)

这是我的代码:

from math import factorial#导入math库里的factorial方法(阶乘方法)
a = []#新建空列表
for i in range(1,int(input()) + 1):#遍历1至输入的数
    a.append(factorial(i))#阶乘数存入数组
print(sum(a))#快速求和

怎么样,这5行Python很简单吧。

猜你喜欢

转载自blog.csdn.net/MRH0420/article/details/109903224
今日推荐