#P10246. Exciting Days

Exciting Days

Background

There is a saying on the Internet that October 2424 is “Programmers’ Day”, because 10241024 is exactly 2102^{10}, 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 nn months, and month ii has aia_i days.

Define the characteristic value of date month mm day dd as follows: write mm and dd in decimal (with no leading 00), and then concatenate them directly. For example, the characteristic value of March 77 is 3737, and the characteristic value of December 2020 is 12201220.

If the characteristic value of a date is a natural-number power of kk, 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 TT, the number of test cases.

Each test case consists of two lines. The first line contains two positive integers n,kn, k, with the same meanings as in the statement. The second line contains nn positive integers a1,,ana_1,\ldots,a_n, 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 m,dm, d separated by a space, meaning that month mm day dd 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 1111 days, and the second month has 1212 days. We need the characteristic value to be an integer power of 11, which can only be 11. 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 22.

[Constraints].

This problem has 2525 test points, each worth 44 points. In the constraints, n\sum n denotes the sum of nn over all test cases. For example, in the sample, n=14\sum n=14.

Test Point ID TT\le n\sum n\le aia_i\le Special Property
11 11 10001000 k=6k=6
232\sim 3
464\sim 6 33
7117\sim 11 10410^4
121412\sim 14 11 3×1053\times 10^5 10910^9
151715\sim 17 33
181918\sim 19 10410^4 10410^4 n=1n=1
202120\sim 21 9×1049\times 10^4 n9n\le 9
222522\sim 25 3×1053\times 10^5

For all testdata, it is guaranteed that 1T1041\le T\le 10^4, 1n3×1051\le n\le 3\times 10^5, 1n3×1051\le \sum n\le 3\times 10^5, 1ai,k1091\le a_i,k\le 10^9, 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 2×1042\times 10^4.

Translated by ChatGPT 5