Counting Cafeteria Menus
Time limit2sMemory limit256 MB
Count how many distinct dish sets appear when the current set of N out of M dishes shifts forward by one each meal.
- Level
Medium5 of 10
- Topics
- String matching, Array, Math
- Solved
- No attempts yet
Problem
The company cafeteria can cook different dishes, numbered 1 through .
At every meal the cafeteria puts out of those dishes, and each employee eats one of them. The dishes served at a meal are decided by this rule.
If dish was served at the previous meal, dish is served at this meal. If dish was served at the previous meal, dish 1 is served at this meal.
So every served number moves up by one from one meal to the next, and the number after wraps back to 1. Meals go on forever, so every menu you can reach by shifting this meal's menu again and again is served sooner or later.
Younghee just joined the company and wants to know how many different menus the cafeteria serves. She tells you the dish numbers served at this meal. Count the different menus. Two menus are the same when they hold exactly the same dish numbers.
Input
The first line contains the number of test cases . ()
The first line of each test case contains , the number of dishes the cafeteria can cook, and , the number of dishes served at one meal. ()
Each of the next lines contains one dish number served at this meal. () The numbers are distinct and sorted in increasing order.
The sum of over all test cases is at most .
Output
For each test case, print the number of different menus on its own line.