All submissions for this problem are available.
There are N people who live in N different houses, such that P1 lives in house H1, P2 lives in H2 and so on. Your task is to send every person into a different house such that P1 does not go to house H1, P2 does not go to house H2.... and person Pk does not go to house Hk and others can go to any house. Given N and k, how many such different arrangements are possible. If no such arrangement is possible, output 0.
The first line contains T, the number of test cases.
Each test case contains a single line, having two space separated integers- N and K. N is the total number of people, and k is the index such that no person from P1 to Pk goes to his own house.
Output one integer per line, which contains the number of arrangements possible for that test case, modulo 1000000007.
1 <= T <= 10
1 <= N <= 105
0 <= K <= N
|Time Limit:||0.130564 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.5, 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, CLOJ, FS|
Fetching successful submissions
If you are still having problems, see a sample solution here.