Under construction

Still being built. Things may change

Euler's Number

Time limit2sMemory limit512 MB

Summary
Read n and output the partial sum 1/0! + 1/1! + ... + 1/n! as a real number accurate to 1e-12.
Level

Medium4 of 10

Topics
Math, Implementation
Solved
No attempts yet

Problem

Euler's number (you may know it better as just (e)) has a special place in mathematics. You may have encountered (e) in calculus or economics (for computing compound interest), or perhaps as the base of the natural logarithm, ln x, on your calculator.

While e can be calculated as a limit, there is a good approximation that can be made using discrete mathematics. The formula for (e) is:

[e = \sum_{i=0}^{n}{\frac{1}{i!}} = \frac{1}{0!} + \frac{1}{1!} + \frac{1}{2!} + \frac{1}{3!} + \frac{1}{4!} + \cdots]

Note that 0! = 1. Now as n approaches ∞, the series converges to (e). When n is any positive constant, the formula serves as an approximation of the actual value of (e). (For example, at n = 10 the approximation is already accurate to 7 decimals.)

You will be given a single input, a value of n, and your job is to compute the approximation of e for that value of n.

Input

A single integer n, ranging from 0 to 10 000.

Output

A single real number, the approximation of e computed by the formula with the given n. All output must be accurate to an absolute or relative error of at most 10−12.

Examples2

  1. Example 1

    Input
    3
    
    Expected output
    2.6666666666666665
    
  2. Example 2

    Input
    15
    
    Expected output
    2.718281828458995