分拆数 2:SP15257

· · 题解

水题做法

注意到 SPOJ 的讨论区有这样一段话:

Actually no need to read the paper mentioned in other comments. Python library Sympy has already implemented the solution to this problem, all you need is to find it out.

于是我们翻一下 SymPy 的文档,发现有个函数叫 partition 就是计算分拆数的。代码:

from sympy.functions.combinatorial.numbers import partition
print(partition(int(input())))

正经做法

注意到这篇文档里说:

P(n) is computed using the Hardy-Ramanujan-Rademacher formula.

即哈代—拉马努金—拉德马赫尔公式。利用这个东西可以实现 p_n 的亚线性做法。

https://www.bilibili.com/video/BV1oD4y1R7E4/

https://travorlzh.github.io/2023/07/16/integer-partitions.html