Python计算圆周率π小数点后第n位 pi

def make_pi(number):
    tick = 0
    q, r, t, k, m, x = 1, 0, 1, 1, 3, 3
    while True:
        if 4 * q + r - t < m * t:
            tick += 1
            if tick > number:
                break
            yield m
            q, r, t, k, m, x = 10*q, 10*(r-m*t), t, k, (10*(3*q+r))//t - 10*m, x
        else:
            q, r, t, k, m, x = q*k, (2*q+r)*x, t*x, k+1, (q*(7*k+2)+r*x)//(t*x), x+2

digits = make_pi(100)
next(digits)
pi = "3."
for i in digits:
    pi += str(i)

print(pi)
输出
3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067


发表于:2018-01-17 13:53:10

原文链接(转载请保留): http://www.multisilicon.com/blog/a23314955.html

友情链接: MICROIC
首页