Color the boxes

3.3

112 votes
Basic Programming, Basics of Implementation, Implementation
Problem

You are given N boxes that are kept in a straight line. You are also given M colors such that (MN). You cannot change the position of boxes. Determine the number of ways to color the boxes such that if you select any M consecutive boxes then the color of each box is unique.

Since the number could be large, print the answer modulo 109+7.

Input format

Two space-separated integers N and M

Output format

For the provided inputs, print the required answer.

Constraints

1MN106

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

We can color boxes only in two ways i.e. giving color as (1,2) and (2,1).

Editor Image

?