Files
SolutionEuler/solutions/0023/euler_23_s3.py
Sidney Zhang 13d5d27c5a feat(pyproject.toml):添加sympy依赖用于数学计算
📝 feat(0021.AmicableNumbers/readme.md):添加亲和数对文档的中文翻译
 feat(0022):新增欧拉问题22解决方案,包含姓名文件和处理脚本
 feat(0023):新增欧拉问题23解决方案,包含三种实现和文档说明

📝 docs(solutions/0067.MaxPathSum2):新增热带半环理论综述文档

新增关于热带半环(Tropical Semiring)的详细综述文档,涵盖其数学原理、与代数几何的联系(热带几何)、在量子力学与量子信息中的应用,以及其他跨学科应用领域。文档系统性地介绍了热带半环的基本理论结构,包括min-plus/max-plus代数、幂等性与分配律,以及其与全序集和格论的联系。同时深入探讨了热带几何的核心概念(如热带化、热带簇、Amoebas和Newton多边形)及其在代数几何中的应用(如热带Bézout定理、拓扑不变量计算和枚举几何)。文档还综述了热带半环在量子力学(如热带量子理论、非厄米系统特殊点分析)和量子信息(如贝尔不等式分析、热带张量网络)中的前沿应用,并展望了其在密码学、生物信息学等领域的潜力。该文档旨在为相关领域的研究者提供一个全面的理论参考。
2025-12-22 18:27:46 +08:00

68 lines
2.0 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import time
def timer(func):
def wrapper(*args, **kwargs):
start_time = time.time()
result = func(*args, **kwargs)
end_time = time.time()
print(f"{func.__name__} took {end_time - start_time:.6f} seconds")
return result
return wrapper
def sum_of_non_abundant_numbers(limit=28123):
"""
计算所有不能表示为两个盈数之和的正整数之和
参数:
limit: 上限值默认为28123欧拉计划官方推荐值
根据数学证明所有大于28123的数都可以表示为两个盈数之和
返回:
total: 所有满足条件的正整数之和
"""
# 1. 使用筛法预处理所有数的真因数之和高效O(n log n)
divisor_sum = [0] * (limit + 1)
for i in range(1, limit + 1):
for j in range(i * 2, limit + 1, i):
divisor_sum[j] += i
# 2. 找出所有盈数
abundant_numbers = [i for i in range(12, limit + 1) if divisor_sum[i] > i]
# 3. 标记可以表示为两个盈数之和的数
can_be_expressed = [False] * (limit + 1)
abundant_set = list(set(abundant_numbers)) # 用于快速查找
# 遍历盈数对
n_abundant = len(abundant_set)
for i in range(n_abundant):
a = abundant_set[i]
if a > limit:
break
# 从i开始允许两个相同的盈数相加如12+12=24
for j in range(i, n_abundant):
s = a + abundant_set[j]
if s > limit:
break
can_be_expressed[s] = True
# 4. 计算所有不能表示为两个盈数之和的数的和
total = sum(i for i in range(1, limit + 1) if not can_be_expressed[i])
return total
@timer
def main():
# 执行计算
result = sum_of_non_abundant_numbers()
print(f"所有不能表示为两个盈数之和的正整数之和是:{result}")
if __name__ == "__main__":
main()