#P17263. [ICPC 2017 Urumqi R] Friends
[ICPC 2017 Urumqi R] Friends
Problem Description
Some people benefit from large and diverse networks of friends, while others prefer a smaller circle of friends and acquaintances. How about functions.
Consider several functions with coefficients and , denoted by
Here is a prime number and is an integer.
The value of function at an integer is defined as
$$f_i(x) = ((x^{i + 1} \bmod p) + (\mu^{i + 1} \bmod p)) \bmod 7.$$We say a subset of is a circle of friends, if all functions in share the same value at no less than half of positions in . More specifically, a circle of friends is a subset of . It presents functions , and they have the same value at distinct locations in where .
Furthermore, we say a circle of friends is “valuable” if it is maximal. That is to say that each bigger set containing a “valuable circle of friends” is not a circle of friends.
Please find and list all “valuable circles of friends”.
Input Format
The inputs contains several test cases. The first line contains an integer which is the total number of test cases.
For each test case, a line contains two integers and where is a prime number and .
Output Format
For each test case, if the total number of “valuable circles of friends” is , output lines.
Each of the first lines outputs a subset of , each of which should be a list of sorted numbers. All valuable circles of friends should be outputted according to the lexicographic order. The last line contains the string “END” as a terminator.
2
5 3
7 4
0 4
1
2
3
END
0 3 6
1 4
2 5
END