#P4071. [SDOI2016] 排列计数

    ID: 2978 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>递推2016各省省选山东枚举,暴力线性递推,递推式逆元

[SDOI2016] 排列计数

Description

Count the number of permutations aa of 11 to nn such that there are exactly mm positions ii with ai=ia_i = i.

Output the answer modulo 109+710^9 + 7.

Input Format

There are multiple test cases in a single test file.

The first line contains an integer TT, representing the number of test cases.

The following TT lines each describe one test case.

For each test case, a single line contains two integers nn and mm, in that order.

Output Format

Output TT lines. For each test case, output one integer representing the answer.

5
1 0
1 1
5 2
100 50
10000 5000
0
1
20
578028887
60695423

Hint

Constraints

This problem contains 20 test points, evenly divided. The constraints for each test point are shown in the table below.

Test point ID T=T = n,mn, m \leq Test point ID T=T = n,mn, m \leq
131 \sim 3 10310^3 88 101210 \sim 12 10310^3 10310^3
464 \sim 6 1212 131413 \sim 14 5×1055 \times 10^5
797 \sim 9 100100 152015 \sim 20 10610^6

For all test points, it is guaranteed that 1T5×1051 \leq T \leq 5 \times 10^5, 1n1061 \leq n \leq 10^6, 0m1060 \leq m \leq 10^6.

Translated by ChatGPT 5