数学中国

 找回密码
 注册
搜索
热搜: 活动 交友 discuz
查看: 1717|回复: 1

这是什么网站?进不去啊

[复制链接]
发表于 2022-5-16 17:55 | 显示全部楼层 |阅读模式
 楼主| 发表于 2026-7-23 10:48 | 显示全部楼层
def isqrt(n):
    """纯整数平方根(牛顿迭代法),无任何浮点运算"""
    if n < 0:
        raise ValueError("Square root not defined for negative numbers")
    if n == 0:
        return 0
    # 初始猜测值使用位运算,避免浮点转换
    x = 1 << ((n.bit_length() + 1) // 2)
    while True:
        y = (x + n // x) // 2
        if y >= x:
            return x
        x = y

def compute_exact_100m_digits():
    # 目标精度:1亿位小数
    SCALE = 10 ** 100000000
   
    # 步骤1: 用纯整数计算 sqrt(2) * SCALE
    # 即计算 sqrt(2 * SCALE^2) 的整数部分
    sqrt2_scaled = isqrt(2 * SCALE * SCALE)
   
    # 步骤2: 计算 7441 + 6305*sqrt(2),全部放大 SCALE 倍
    # 注意:sqrt2_scaled 已经是 sqrt(2)*SCALE
    inner = 7441 * SCALE + 6305 * sqrt2_scaled
   
    # 步骤3: 计算 sqrt(inner / 4096) * SCALE
    # = sqrt(inner * SCALE^2 / 4096)
    # = sqrt(inner * SCALE^2) // 64
    numerator_scaled = isqrt(inner * SCALE * SCALE)
    result_scaled = numerator_scaled // 64
   
    # 步骤4: 转换为字符串并插入小数点
    s = str(result_scaled).zfill(100000001)  # 确保位数足够
    integer_part = s[:-100000000]
    decimal_part = s[-100000000:]
   
    return f"{integer_part}.{decimal_part}"

# &#9888;&#65039; 警告:此计算需要约 2-4 GB 内存和数十分钟至数小时CPU时间
# result = compute_exact_100m_digits()
# with open("exact_100m.txt", "w") as f:
#     f.write(result)
print("代码已就绪。取消注释最后三行即可开始纯整数精确计算。")
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|数学中国 ( 京ICP备05040119号 )

GMT+8, 2026-7-26 23:06 , Processed in 0.167141 second(s), 16 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表