Problems > Onto Functions

Onto Functions

Difficulty: 2000 5000 ms 128 MB

combinatorics

Count the surjective (onto) functions from an N-element set to a K-element set, modulo 109+7.

Input: one line with two integers N and K.

Output: the number of surjections mod 109+7.

Constraints:

  • 1 ≤ K ≤ N ≤ 106

Sample Tests

Input 1
3 2
Output 1
6
Input 2
2 2
Output 2
2

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.