All submissions for this problem are available.
A chain is a series of connected links. David has been presented a chain for his birthday consisting of N links and would like to color each of the links into one of M colors. He would like the coloring to be pretty uniform, so that no color is used too often or too seldom. Finally, David came with the following restriction: he wants to color the links in such a way that every color is used at least once in every M+1 consecutive links.
Two colorings are considered different if there exists at least one i between 1 and N such that link i is colored differently in these colorings. (The links are numbered, and the chain can not be rotated.) How many ways are there for David to color the chain?
The first line of the input file contains one integer T -- the number of test cases (no more than 10). Each of the next T lines contains two integers N and M -- the length of the chain presented to David and the number of colors (1 ≤ M < N ≤ 105).
For each test case output the number of ways for David to color the chain modulo 1 000 000 007 (109 + 7).
Input: 3 2 1 4 2 6 3 Output: 1 10 132
|Tags||cook16, gennady.korotkevich, medium|
|Time Limit:||0.133877 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, PYP3, CLOJ, FS|
Fetching successful submissions
If you are still having problems, see a sample solution here.