F - Total Product is N 解説 by en_translator
Original proposer: vwxyz
Let \(N\) be the divisors of \(d_1,d_2,\dots,d_K\).
When choosing \(b\) elements from \(d_1,d_2,\dots,d_K\), let \(c\) be their total product, and call their sum as its score.
Let \(dp0_{a,b,c}\) be the number of all such choices, and \(dp1_{a,b,c}\) be the sum of their scores. (DP stands for Dynamic Programming.)
Then the answer is \(\sum_{b=1}^{\infty}{dp1_{K,b,N}} \times b!\pmod{998244353}\).
If \(c\) is a multiple of \(d_e\),
\(dp0_{a,b,c}=dp0_{a-1,b-1,\frac{c}{d_a}}+dp0_{a-1,b,c}\)
\(dp1_{a,b,c}=dp1_{a-1,b-1,\frac{c}{d_a}}+dp0_{a-1,b-1,\frac{c}{d_a}} \times d_a+dp1_{a-1,b,c}.\)
If \(c\) is not a multiple of \(d_e\),
\(dp0_{a,b,c}=dp0_{a-1,b,c}\)
\(dp1_{a,b,c}=dp1_{a-1,b,c}\).
It is sufficient to track the states where \(a\) and \(c\) are divisors of \(N\).
For \(1 \leq N \leq 10^{10}\), \(N\) has at most \(2304\) divisors.
Also, \(\prod_{i=1}^{14}{i}>10^{10}\), so it suffices to consider \(b\) up to \(14\).
Hence, \(dp0\) and \(dp1\) can be computed in \(O(14 \times 2304^2)\) time, which is fast enough.
投稿日時:
最終更新: