#P13187. [GCJ 2016 Qualification] Coin Jam
[GCJ 2016 Qualification] Coin Jam
题目描述
A jamcoin is a string of digits with the following properties:
- Every digit is either or .
- The first digit is and the last digit is .
- If you interpret the string in any base between and , inclusive, the resulting number is not prime.
Not every string of s and s is a jamcoin. For example, is not a jamcoin; its interpretation in base is , which is prime. But the string is a jamcoin: in bases through , its interpretation is , and , respectively, and none of those is prime.
We hear that there may be communities that use jamcoins as a form of currency. When sending someone a jamcoin, it is polite to prove that the jamcoin is legitimate by including a nontrivial divisor of that jamcoin's interpretation in each base from to . (A nontrivial divisor for a positive integer is some positive integer other than 1 or that evenly divides .) For convenience, these divisors must be expressed in base .
For example, for the jamcoin mentioned above, a possible set of nontrivial divisors for the base through 10 interpretations of the jamcoin would be: , and , respectively.
Can you produce different jamcoins of length , along with proof that they are legitimate?
输入格式
The first line of the input gives the number of test cases, . test cases follow; each consists of one line with two integers and .
输出格式
For each test case, output lines. The first line must consist of only Case #x
:, where is the test case number (starting from 1). Each of the last lines must consist of a jamcoin of length followed by nine integers. The -th of those nine integers (counting starting from 1) must be a nontrivial divisor of the jamcoin when the jamcoin is interpreted in base .
All of these jamcoins must be different. You cannot submit the same jamcoin in two different lines, even if you use a different set of divisors each time.
1
6 3
Case #1:
100011 5 13 147 31 43 1121 73 77 629
111111 21 26 105 1302 217 1032 513 13286 10101
111001 3 88 5 1938 7 208 3 20 11
提示
In this sample case, we have used very small values of and for ease of explanation. Note that this sample case would not appear in either the Small or Large datasets.
This is only one of multiple valid solutions. Other sets of jamcoins could have been used, and there are many other possible sets of nontrivial base divisors. Some notes:
- 110111 could not have been included in the output because, for example, it is 337 if interpreted in base 3 $(1\times 243 + 1\times 81 + 0\times 27 + 1\times 9 + 1\times 3 + 1\times 1)$, and is prime.
- 010101 could not have been included in the output even though 10101 is a jamcoin, because jamcoins begin with .
- 101010 could not have been included in the output, because jamcoins end with 1.
- 110011 is another jamcoin that could have also been used in the output, but could not have been added to the end of this output, since the output must contain exactly examples.
- For the first jamcoin in the sample output, the first number after 100011 could not have been either or , because those are trivial divisors of (100011 in base ).
Limits
- . (There will be only one test case.)
- It is guaranteed that at least distinct jamcoins of length exist.
Small dataset (10 Pts, Test Set 1 - Visible)
- .
- .
Large dataset (20 Pts, Test Set 2 - Hidden)
- .
- .
Note that, unusually for a Code Jam problem, you already know the exact contents of each input file. For example, the Small dataset's input file will always be exactly these two lines:
1
16 50
So, you can consider doing some computation before actually downloading an input file and starting the clock.