P1729 Compute e

Background

The final chapter of "The Story of Love and Sorrow II · compute". The base of the natural logarithm $e$ is a famous irrational number, approximately $2.718281828\cdots$. There is a formula to compute $e$: $$e=\sum_{n=0}^{\infty}\frac{1}{n!}$$ Here $n!$ denotes the factorial of $n$, that is, $n!=1\times 2\times 3\times \cdots \times n$.

Description

"Yueluo Wuti" actually replied with 10,000 digits after the decimal point of $\pi$ so quickly?! Impossible—he must have asked someone. The master "Love and Sorrow" makes it difficult for "Yueluo Wuti" again: "Help me compute the first $n$ digits after the decimal point of $e$ ($n \le 10000$), hurry!!!" "Yueluo Wuti" wants to ask someone, but he finds that talking to you just now has drained his phone battery. At this critical moment, he can only rely on himself. If you were him now, how would you write this program?

Input Format

Only one line: $n$.

Output Format

Multiple lines. First line: $2$. Starting from the second line: the fractional part of $e$. Insert a space after every 10 digits, and a newline after every 50 digits.

Explanation/Hint

30% testdata: $n \le 1000$. 100% testdata: $n \le 10000$. Time limit: 1 second. Translated by ChatGPT 5