Question 1: Magic Series time limit: 256 ms single point time limit: Ms memory limit: MB
Description
She is a digital-loving child. She is always thinking about the connection between life and mathematics. One day, she found that the design of the Gregorian calendar was exquisite.
Every four years, there will be one more day, and every one hundred years there will be another year not a leap year, And 400th years is a leap year. In this way, each year has an average of four hundred and 97 days out of 365 in the 400-year cycle.
The rule described above is 100-4 + 1 = 97.
The great God wants to know if every natural number can be expressed in the above form. Specifically, the great God wants to write a natural number N into A1-A2 + A3-A4 +... In the format
A1 is a multiple of A2, A2 is a multiple of A3, and so on. In addition, if she doesn't want to make the problem boring, she adds some additional conditions:
1. Among them, Ai =aj (I =j), that is, the first two adjacent numbers must be at least twice or more than the last one.
2. The length of a series must be at least 3 and cannot exceed 100. (you can find the answer if the series is too long ).
3. Each number in the constructed series cannot be too large. Therefore, I hope that each number in the series will be a positive integer smaller than 263.
After thinking for a while, I found the problem was not that simple. Now she turned to you and hoped that you could help her solve the problem.
Input
The first row contains a number T, indicating the number of data groups.
Next, it contains the T group of data. Each group contains a row of data, including an integer N.
Output
For each group of data, a row "Case X:" Is output. X indicates the number of each group of data (starting from 1), and a string "no solution" indicates no solution, alternatively, the output column {Ai} is separated by spaces. If multiple columns meet the requirements, output any group.
Data range
Small Data:
1 ≤ T ≤ 10
1 ≤ N ≤100
Big Data:
1 ≤ T ≤1000
1 ≤ N ≤1018
-
Sample Input
-
2197
-
Sample output
-
Case 1: no solutionCase 2: 100 4 1
Question 2: String compression time limit: 256 ms single point of time limit: Ms memory limit: MB
Description
There is a mysterious file on your hard disk that occupies a lot of space. You decide to compress it to save space. Unfortunately, you have not installed any compression software, so you decided to write a compression program by yourself. You find that this is a text file, including many lines. Each line is a string with exactly the length of L, and the strings may be repeated. The order of rows is not important. In other words, after the order is disrupted, the file content can still be considered the same as the original content.
For example, the content of this file can be as follows:
Bar
Car
Bat
Cat
Cat
After a period of observation, you found that the characters in the same column are often the same, so you designed a simple compression framework. First, adjust the order of rows with a certain policy, and then convert all strings into a single string in the first column and then the following order. For example, in the preceding example, if the sequence is not adjusted, the values are directly changed:
Bcbccaaa1_rttt
Then use the RLE to compress the transformed string:
1b1c1b2c5a2r3t
Of course, you can change the order first:
Car
Cat
Cat
Bat
Bar
The following compression string is used:
3c2b5a1r3t1r
It is a little shorter than not adjusting the order.
Now you have two different compression strings. If you want to know whether the files they decompress are the same, please write a program to solve this problem.
Input
The first line is an integer T (T <= 30), indicating the number of test data groups.
Each group of test data occupies three rows. The first integer, L, indicates the length of each string in the original file. The second and third lines are two compressed strings, in the format of c1 n1 c2 n2... CMnM, indicating that the character ci appears continuously ni times. For the specific format, see the example. The input string contains only lowercase letters a to z. Make sure that the compressed string is valid and not empty.
Output
For each group of test data, "Case x:" Is output first, where "x" indicates the test data number. If the two compression strings correspond to the same file content, "Yes" is output; otherwise, "No" is output ".
Data range
Small Data: 1 <= L <= 10, 1 <= ni <= 100, the length of the compressed string cannot exceed 10 ^ 4
Big Data: 1 <= L <= 1000, 1 <= ni <= 10 ^ 9, the length of the compressed string cannot exceed 10 ^ 6
-
Sample Input
-
231b1c1b2c5a2r3t3c2b5a1r3t1r220a20b10a20b10a20a20b20a20b
-
Sample output
-
Case 1: YesCase 2: No
Question 3: set time limit: 256 ms single point time limit: Ms memory limit: MB
Description
Count the number of set pairs (A, B) that meet the following conditions:
Both A and B are {1, 2 ,..., Subset of N;
A and B have no common elements;
F (A) <= f (B ). F (S) is defined as the bitwise variance or sum of all elements in S. For example, f ({}) = 0, f ({1, 3}) = 2.
Because the answer may be very large, you just need to find the remainder of it divided by M.
Input
The first line is an integer T (1 ≤ T ≤ 10), indicating the number of data groups.
Next, there is no blank line between the input data of the T group and the test data.
The data format of each group is as follows:
Only one row, two integers N and M (1 ≤ M ≤ 108 ).
Output
For each group of data, "Case x:" Is output first, followed by an integer, indicating the result.
Data range
Small Data: 1 ≤ N ≤ 20
Big Data: 1 ≤ N <212
-
Sample Input
-
13 100000000
-
Sample output
-
Case 1: 18