Array splitting
Time limit1sMemory limit256 MB
Repeatedly quarter an N by M array until a side reaches 1, then list each distinct strip length with its count modulo 1234567891.
- Level
Medium7 of 10
- Topics
- Divide and conquer, Recursion, Combinatorics, Math
- Solved
- No attempts yet
Problem
Divide and conquer on a two dimensional array keeps cutting the array into smaller pieces. This problem counts the pieces that are left at the end.
An array of size splits into four arrays whose sizes are as close to each other as possible: , , , and . Here is rounded down and is rounded up. For example, a array splits into two arrays and two arrays, and a array splits into a , a , a , and a array.
If either side of the array you are looking at has length 1, that array is kept as it is and is never split again. Running the process to the end therefore leaves the original array as a collection of arrays. A array is a rotated array, so the two count as one kind.
Given and , report how many kinds of arrays are left once the splitting is finished, together with and the count for each kind.
Input
The first line has the number of test cases ().
Each of the next lines has the starting size of an array, and (), separated by one space.
Output
For each test case, first print on its own line the number of kinds of arrays left after the splitting. Call this value .
Then print lines, each holding and the count for that kind separated by one space. Print the values of in increasing order. A count can be very large, so print it modulo 1,234,567,891. A kind whose count is 0 after the modulo still adds to and is still printed.
Do not print a blank line between test cases.