题目的链接
http://noi.openjudge.cn/ch0105/35/
#include <bits/stdc++.h> //通用头文件
using namespace std; //名字空间
int main()
{
long long n,t=1;
double s=1;
cin>>n;
for(int i=1;i<=n;i++)
{
t*=i;
s+=1.0/t;
}
printf("%.10lf\n", s);
return 0;
}
python代码
n = int(input())
sum = 0
def jc(a): #求阶乘
num = 1
for i in range(a + 1):
if i != 0:
num *= i
return num
for i in range(n + 1):
sum += 1 / jc(i)
print('{:.10f}'.format(sum))
参考链接
Python编程PTA题解——求e的近似值
https://blog.csdn.net/qq_43479432/article/details/104991866
Python数学小实验——自然对数e的理解
https://blog.csdn.net/weixin_45342712/article/details/95969979