Algorithm Final Exam
Time limit1sMemory limit128 MB
Count permutations of N items in which the first k positions are all wrong.
- Level
Medium5 of 10
- Topics
- Combinatorics, Math
- Solved
- No attempts yet
Problem
The algorithm final exam asks for one thing only, connecting terms to definitions with lines. The left column lists terms and the right column lists definitions, each in a single row, and a student draws one line from every term to a definition. Two different terms go to two different definitions, so one answer sheet is a permutation that maps terms to definitions.
Seonyeong trusted her programming skill and did not study. The exam had nothing to do with programming, so she guesses every line.
Let be the number of answer sheets in which the first terms from the top are all wrong once Seonyeong has drawn every line. The remaining terms may be right or wrong.
Given and , write a program that computes .
Input
The first line contains the number of test cases. Each test case is one line holding the test case number and two integers and , separated by spaces. (, )
Output
For each test case, print the test case number given in the input and on one line, separated by a single space.