#P7092. Subset Partition Summation
Subset Partition Summation
Subset Partition Summation
We are given two integers (n) and (k). Let (P) be the set of all primes less than or equal to (n). Define the set (T) as all numbers that can be written as a product of one or more primes from (P). In other words, (T) is the set of all square‐free numbers whose prime factors are all (\le n). Note that by definition the number 1 is not included in (T).
For any nonempty subset (S \subseteq T), define its product [ X(S)=\prod_{i\in S}i. ] We are interested only in those subsets (S) for which (X(S)) is squarefree. (Recall that for a squarefree number (m=\prod_{p\in A}p) we have (\mu(m)=(-1)^{|A|}) and (\varphi(m)=m\prod_{p\in A}(1-\frac1p)=\prod_{p\in A}(p-1)). Thus for such (m) we get [ \mu(m)\varphi(m)=\prod_{p\in A}(1-p). ])
A key observation is that every valid subset (S) that yields a squarefree product gives rise to a unique subset (A \subseteq P) (namely the union of the prime factors of all elements of (S)). In fact, every nonempty subset (A\subseteq P) can be obtained in many ways. In particular, if (A) has (r) elements then any partition of (A) into nonempty blocks corresponds to a way to represent (\prod_{p\in A}p) as (X(S)) for some valid (S, () note that the block (B) corresponds to the unique number (\prod_{p\in B}p) from (T) ). The number of partitions of a set of size (r) is given by the Bell number (B(r)).
Hence the required sum is [ \sum_{\substack{S\subset T\S\neq\varnothing}} \mu\Bigl(\prod_{i\in S}i\Bigr)\varphi\Bigl(\prod_{i\in S}i\Bigr)= \sum_{\varnothing\neq A\subseteq P} B(|A|)\prod_{p\in A}(1-p),. ] However, to allow for partial scoring and to control the complexity, an additional parameter (k) is given. In our problem, the summation is restricted to those subsets (A\subseteq P) with (|A|\le k). That is, you are to compute [ \sum_{r=1}^{\min{k,|P|}} ; \left(\sum_{\substack{A\subseteq P\|A|=r}} \prod_{p\in A}(1-p)\right) B(r) \pmod{998244353},. ]
Your task is to calculate the above sum modulo (998244353).
Input Format
The input consists of a single line containing two integers \(n\) and \(k\) separated by a space.Constraints
- \(1 \le n \le 10^6\)
- \(1 \le k \le \pi(n)\) (where \(\pi(n)\) is the number of primes \(\le n\))
Output Format
Output one integer: the value of the sum modulo \(998244353\).Explanation
For example, when \(n=5\), we have \(P=\{2,3,5\}\). If \(k\) is chosen as 2 then the sum is taken only over the subsets of \(P\) of size 1 and 2.inputFormat
The input contains a single line with two integers n and k.
For example:
5 2
outputFormat
Output a single integer which is the sum defined in the problem statement modulo 998244353.
sample
5 2
998244078