• 个人简介

    🔖 三角洲签名

    头,甲,枪,包,花来!夺舍成功

    --点击查看完整夺舍经历--
    • 零号大坝:怀表,M250
    • 长弓溪谷:房卡,灭队
    • 绝密巴克什:刘涛,m14
    • 航天基地:没进过......
    🎉 持续夺舍中 | 🌌 正在大坝跑刀

    🌐 你想计算圆周率吗?

    from decimal import Decimal, getcontext
    import math
    getcontext().prec = 1000 # 设置计算精度(x)
    def calculate_pi_chudnovsky(terms):
        sum = Decimal(0)
        D640320 = Decimal('640320')  
        sqrt640320 = D640320.sqrt()
        for k in range(terms):
            numerator = Decimal((-1)**k) * math.factorial(6*k) * (13591409 + 545140134*k)
            denominator = math.factorial(3*k) * (math.factorial(k)**3) * (D640320**(3*k + Decimal(1.5)))
            term = Decimal(numerator) / Decimal(denominator)
            sum += term
            pi_estimate = Decimal(1) / (Decimal(12) * sum)
            print(f"第{k+1}次计算:π ≈ {pi_estimate}")
        return pi_estimate
    calculate_pi_chudnovsky(1)#算几次(x)
    

    注明:这个代码是借鉴了G12 纪鑫睿 @

  • 最近活动

    This person is lazy and didn't join any contests or homework.