7008.Counting Sequences

Time Limit: 1s Memory Limit: 512MB

Your task is to count the number of sequences of length $n$ where each element is an integer between $1 \dots k$ and each integer between $1 \dots k$ appears at least once in the sequence.

For example, when $n=6$ and $k=4$ , some valid sequences are $[1,3,1,4,3,2]$ and $[2,2,1,3,4,2]$ .

Input Format(From the terminal/stdin)

The only input line has two integers $n$ and $k$ .

  • $1 \le k \le n \le 10^6$

Output Format(To the terminal/stdout)

Print one integer: the number of sequences modulo $10^9+7$ .

Sample Input

Copy
6 4
 · \n

Sample Output

Copy
1560
    \n
Source: CSES, Counting Problems, 2228

Submit

请先 登录

© 2025 FAQs