题目描述
求阶乘,不过很恶心呐,测试点用大数,错完改python
样例
输入:23
输出:27029669736328405580313
python代码
n=int (input());
sum=0;
if n==0:
print(1);
else :
for i in range(1,n+1):
mod=1;
for j in range(1,i+1):
mod=mod*j;
sum+=mod;
print(sum);
代码2
python的库没深学,后面用ai才知道python自带求阶乘的库,伟大无需多言
import math
def factorial_sum(n):
sum_ = 0
if n == 0:
return 1
for i in range(1, n + 1):
mod = math.factorial(i)
sum_ += mod
return sum_
n = int(input())
result = factorial_sum(n)
print(result)