跳到正文

题解

分拆数 2:SP15257

stripe_python约 1 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2025年12月12日
篇幅
约 1 分钟
题目
SP15257

版本

  1. v1当前

水题做法

注意到 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 就是计算分拆数的。代码:

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

正经做法

注意到这篇文档里说:

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

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

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

nn 小则暴力,大则级数求和。

原文