#P9034. 「KDOI-04」Again Counting Set

    ID: 8092 Type: RemoteJudge 2000ms 512MiB Tried: 0 Accepted: 0 Difficulty: 6 Uploaded By: Tags>数学洛谷原创O2优化枚举洛谷月赛分类讨论

「KDOI-04」Again Counting Set

题目背景

题目描述

小 S 不喜欢集合,不喜欢自然数,不喜欢求和,不喜欢求积,不喜欢最小值,不喜欢最大值,不喜欢 mex⁡\operatorname{mex},所以有了这题。

给出 n,kn,k,求有多少个可重整数集合 SS 满足:

  • ∣S∣=k|S|=k;
  • 对于任意 x∈Sx\in S,0≤x≤n0\le x\le n;
  • ∏x∈Sx=min⁡x∈Sx\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)}$。

注: mex\bf{mex} 指集合中没有出现过的最小的自然数。

输入格式

本题包含多组测试数据。

输入的第一行包含一个正整数 TT,表示测试数据组数。

对于每组测试数据,输入包含一行两个正整数 n,kn,k。

输出格式

对于每组测试数据,输出一行一个整数表示答案。

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

提示

【补充说明】

为了更好的让选手理解题面,给出若干合法/不合法集合例子:

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

该集合是一个符合要求的集合,因为 0×1×2×2=0=min⁡{0,1,2,2}0\times 1\times 2\times 2=0=\min\{0,1,2,2\},$0+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\}

该集合不是一个符合要求的集合,因为虽然 $3+5=8,\min\{3,5\}+\max\{3,5\}+\operatorname{mex}\{3,5\}=3+5+0=8$,但是 3×5≠min⁡{3,5}3\times 5\not=\min\{3,5\}。

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

该集合不是一个符合要求的集合,因为虽然 $1\times 9\times 1\times 9\times 8\times 1\times 0=0=\min\{1,9,1,9,8,1,0\}$,但是其和为 2929 而并非 min⁡+max⁡+mex⁡=0+9+2=11\min+\max+\operatorname{mex}=0+9+2=11。

【数据范围】

对于 100%100\% 的数据,保证 1≤T≤1061\le T\le10^6,1≤n,k≤10181\le n,k\le10^{18}。

测试点编号 分值 T≤T\le k≤k\le nn
11 1010 55 ≤5\le5
22 10510^5 101810^{18} =1=1
33 =2=2
44 =3=3
55 =4=4
66 =5=5
77 1010 ≤10\le10
88 10310^3 ≤103\le10^3
99 10610^6 101810^{18} ≤108\le10^{8}
1010 ≤1018\le10^{18}