Problems > Partitions into K Groups

Partitions into K Groups

Difficulty: 1800 6000 ms 128 MB

combinatorics

Count the ways to partition N labelled items into exactly K non-empty unlabelled groups — the Stirling number S(N, K) — modulo 109+7.

Input: one line with two integers N and K.

Output: S(N, K) mod 109+7.

Constraints:

  • 1 ≤ K ≤ N ≤ 106

Sample Tests

Input 1
4 2
Output 1
7
Input 2
3 3
Output 2
1

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.