#P10246. Exciting Days
Exciting Days
Background
There is a saying on the Internet that October is “Programmers’ Day”, because is exactly , and computers are closely related to binary.
If an alien civilization does not use the Earth calendar, and may not even use traditional binary computers, would they have a similar tradition?
Problem Description
On a certain planet, the calendar is numerically different from Earth’s, but its structure is generally similar. Specifically, a year has months, and month has days.
Define the characteristic value of date month day as follows: write and in decimal (with no leading ), and then concatenate them directly. For example, the characteristic value of March is , and the characteristic value of December is .
If the characteristic value of a date is a natural-number power of , then this date is called a generalized Programmers’ Day. Can you find all generalized Programmers’ Days on this planet?
Input Format
This problem has multiple test cases. The first line of the input contains a positive integer , the number of test cases.
Each test case consists of two lines. The first line contains two positive integers , with the same meanings as in the statement. The second line contains positive integers , representing the number of days in each month.
Output Format
For each test case, first output one line containing a non-negative integer, the number of generalized Programmers’ Days. Then output several lines, each containing a pair of positive integers separated by a space, meaning that month day is a Programmers’ Day.
Within the same test case, the dates should be printed in the order they occur in the year.
2
2 1
11 12
12 2
31 29 31 30 31 30 31 31 30 31 30 31
0
7
1 6
1 28
3 2
5 12
6 4
10 24
12 8
Hint
[Sample Explanation].
For the first test case, the aliens’ calendar has two months: the first month has days, and the second month has days. We need the characteristic value to be an integer power of , which can only be . However, the characteristic value of any date has at least two digits, so there is no valid date.
For the second test case, this is the Gregorian calendar of humans in a leap year. It is easy to see that the characteristic values of the printed dates are indeed natural-number powers of .
[Constraints].
This problem has test points, each worth points. In the constraints, denotes the sum of over all test cases. For example, in the sample, .
| Test Point ID | Special Property | |||
|---|---|---|---|---|
For all testdata, it is guaranteed that , , , , and all inputs are integers.
To avoid excessive constant-factor optimizations, it is guaranteed that, for a single test point, the number of printed dates does not exceed .
Translated by ChatGPT 5