#P9034. 「KDOI-04」Again Counting Set

    ID: 9911 远端评测题 2000ms 512MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>数学2023洛谷原创O2优化枚举洛谷月赛分类讨论

「KDOI-04」Again Counting Set

Background

Problem Description

Little S does not like sets, does not like natural numbers, does not like summation, does not like products, does not like minimum values, does not like maximum values, and does not like mex\operatorname{mex}, so this problem exists.

Given n,kn, k, find how many multisets of integers SS satisfy:

  • S=k|S| = k.
  • For any xSx \in S, 0xn0 \le x \le n.
  • $\displaystyle{\prod_{x \in S} x = \min_{x \in S} x}$.
  • $\displaystyle{\sum_{x \in S} x = \min_{x \in S} x + \max_{x \in S} x + {\operatorname{mex}}(S)}$.

Note: mex\bf{mex} is the smallest natural number that does not appear in the set.

Input Format

This problem contains multiple test cases.

The first line of input contains a positive integer TT, which denotes the number of test cases.

For each test case, the input contains one line with two positive integers n,kn, k.

Output Format

For each test case, output one line with one integer representing the answer.

7
1 4
2 4
5 3
2 100
3 8
20 50
499122178 4
1
2
0
3
5
39
998244353

Hint

Additional Notes.

To help contestants understand the statement better, here are several examples of valid/invalid sets:

  • {0,1,2,2}\{0, 1, 2, 2\}.

This set satisfies the requirements, because $0 \times 1 \times 2 \times 2 = 0 = \min\{0, 1, 2, 2\}$, and 0+1+2+2=50 + 1 + 2 + 2 = 5, $\min\{0, 1, 2, 2\} + \max\{0, 1, 2, 2\} + \operatorname{mex}\{0, 1, 2, 2\} = 0 + 2 + 3 = 5$.

  • {3,5}\{3, 5\}.

This set does not satisfy the requirements, because although 3+5=83 + 5 = 8, $\min\{3, 5\} + \max\{3, 5\} + \operatorname{mex}\{3, 5\} = 3 + 5 + 0 = 8$, we have 3×5min{3,5}3 \times 5 \ne \min\{3, 5\}.

  • {1,9,1,9,8,1,0}\{1, 9, 1, 9, 8, 1, 0\}.

This set does not satisfy the requirements, because although $1 \times 9 \times 1 \times 9 \times 8 \times 1 \times 0 = 0 = \min\{1, 9, 1, 9, 8, 1, 0\}$, its sum is 2929, not min+max+mex=0+9+2=11\min + \max + \operatorname{mex} = 0 + 9 + 2 = 11.

Constraints

For 100%100\% of the testdata, it is guaranteed that 1T1061 \le T \le 10^6, 1n,k10181 \le n, k \le 10^{18}.

Test Point ID Score TT \le kk \le nn
11 1010 55 5\le 5
22 10510^5 101810^{18} =1= 1
33 =2= 2
44 =3= 3
55 =4= 4
66 =5= 5
77 1010 10\le 10
88 10310^3 103\le 10^3
99 10610^6 101810^{18} 108\le 10^{8}
1010 1018\le 10^{18}

Translated by ChatGPT 5