现在的位置: 首页 > 综合 > 正文

sicily Computing PI

2017年02月07日 ⁄ 综合 ⁄ 共 340字 ⁄ 字号 评论关闭

DescriptionTime
Limit: 1sec Memory Limit:256MB
You can approximate PI by using the following series:
PI = 4(1 - 1/3 + 1/5 - 1/7 + 1/9 - ... -1/(2i-1) + 1/(2i+1))

Input

An integer i (0<i<=100000).


Output

The PI value.

You should set the precision to 15.


Sample Input

Copy sample input to clipboard

10


Sample Output

3.232315809405593


一开始老是超时,最后放弃了按顺序叠加的方法(因为那要频繁计算一个pow(-1,n)),而是把加法看成两段,奇偶分开算,就没超时了。

抱歉!评论已关闭.