Natural constant e can stages . 1 + . 1 / . 1 ! + . 1 / 2 ! + ⋯ + . 1 / n- ! + ⋯ be approximated. This problem requires a given non-negative integer n, the number of stages required before the n- + . 1 items and.
Input formats:
Input of the first row given non-negative integer n-( ≤ . 1 0 0 0) .
Output formats:
Value output portion and in a row, eight decimal places.
Sample input:
10
Sample output:
2.71828180
1 # 求e的近似值
2 # Author: cnRick
3 # Time : 2020-3-28
4 def factor(n):
5 if n == 0:
6 return 1.0
7 result = 1.0
8 for i in range(1,n+1):
9 result *= i
10 return result
11
12 n = int(input())
13 result = 0
14 for i in range(0,n+1):
15 result += 1/factor(i)
16 print("{:.8f}".format(result))