Project Euler 772
Project Euler 772
题目
Balanceable \(k\)-bounded partitions
A \(k\)-bounded partition of a positive integer \(N\) is a way of writing \(N\) as a sum of positive integers not exceeding \(k\).
A balanceable partition is a partition that can be further divided into two parts of equal sums.
For example, \(3 + 2 + 2 + 2 + 2 + 1\) is a balanceable \(3\)-bounded partition of \(12\) since \(3 + 2 + 1 = 2 + 2 + 2\). Conversely, \(3 + 3 + 3 + 1\) is a \(3\)-bounded partition of \(10\) which is not balanceable.
Let \(f(k)\) be the smallest positive integer \(N\) all of whose \(k\)-bounded partitions are balanceable. For example, \(f(3) = 12\) and \(f(30) \equiv 179092994 \pmod {1\,000\,000\,007}\).
Find \(f(10^8)\). Give your answer modulo \(1\,000\,000\,007\).
解决方案
暴力枚举出\(f\)的前几项,在OEIS中查询得到结果为A051426。
标题直接给出\(f(n)=\text{lcm}(2,4,6,\dots,n)=2\cdot\text{lcm}(1,2,3,\dots,n)\)
那么为了计算\(\text{lcm}(1,2,3,\dots,n)\),直接枚举出\(n\)以内的所有质数\(p_i\),找到对应最大的\(e_i\)使得\(p_i^{e_i}\le n\),直接相乘即可。
代码
1 |
|