def jiecheng(n):
if n ==1:
return 1
else:
return jiecheng(n-1)*n
kk=int(input())
a=jiecheng(kk)
# print(a)
sum=0
for i in range(1,kk+1):
sum+=jiecheng(i)
print(sum)
- 阶乘函数定义,以为自己会了还是想了半天,还是要自己动手编程 才行
- 连续求和,不要想得太复杂
def jiecheng(n):
if n ==1:
return 1
else:
return jiecheng(n-1)*n
kk=int(input())
a=jiecheng(kk)
# print(a)
sum=0
for i in range(1,kk+1):
sum+=jiecheng(i)
print(sum)