#P1727. Calculate π to n Decimal Places
Calculate π to n Decimal Places
Calculate π to n Decimal Places
In this problem, you are required to calculate the digits of π (pi) after the decimal point up to n digits, where n is an integer satisfying \(0 \le n \le 10000\). The output must include the integer part (which is 3) followed by a decimal point and then exactly n digits without rounding.
You may use the spigot algorithm for π which iteratively extracts digits using the recurrence based on the formula:
\( x = a[i] \times 10 + \text{carry} \) and \( a[i] = x \mod (2i+1) \).
For example, if n = 5, the output should be: 3.14159.
inputFormat
The input consists of a single integer n (\(0 \le n \le 10000\)) representing the number of digits after the decimal point that need to be computed.
outputFormat
Output the value of \(\pi\) as a string with its integer part, a decimal point, and exactly n digits following the decimal point.
sample
0
3.