python用反正切函数展开式求圆周率值,如下图
def Pi(n):
x1 = 4*10**(n+10)//5
x2 = -10**(n+10)//239
pi = x1+x2
for i in range(3,n*2,2):
x1 //= -5*5
x2 //= -239*239
pi += (x1+x2)//i
pi = 4*pi//10**10
return '3.'+str(pi)[1:]
print(Pi(10))
print(Pi(100))
print(Pi(1000))