#P17263. [ICPC 2017 Urumqi R] Friends

    ID: 19653 远端评测题 3000ms 512MiB 尝试: 0 已通过: 0 显示难度提高+/省选− 上传者: 标签>搜索数学图论2017数论图论建模概率论ICPCbitset

[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 pp and μ(0≤μ<p)\mu (0 \le \mu < p), denoted by

f0,f1,…,fp−1.f_0, f_1, \dots, f_{p-1}.

Here pp is a prime number and μ\mu is an integer.

The value of function fif_i at an integer x∈{0,1,…,p−1}x \in \{0, 1, \dots, p-1\} is defined as

$$f_i(x) = ((x^{i + 1} \bmod p) + (\mu^{i + 1} \bmod p)) \bmod 7.$$

We say a subset SS of {0,1,…,p−1}\{0, 1, \dots, p - 1\} is a circle of friends, if all functions in SS share the same value at no less than half of positions in {0,1,…,p−1}\{0, 1, \dots, p-1\}. More specifically, a circle of friends is a subset S={a1,a2,…,au}S=\{a_1, a_2, \dots, a_u\} of {0,1,…,p−1}\{0, 1, \dots, p-1\}. It presents uu functions fa1,fa2,…,fauf_{a_1}, f_{a_2}, \dots, f_{a_u}, and they have the same value at vv distinct locations in {0,1,…,p−1}\{0, 1, \dots , p - 1\} where 2v≥p2v \ge p.

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 T(1≤T≤210)T (1 \le T \le 2^{10}) which is the total number of test cases.

For each test case, a line contains two integers pp and μ\mu where pp is a prime number and p≤100p \le 100.

Output Format

For each test case, if the total number of “valuable circles of friends” is FF, output F+1F + 1 lines.

Each of the first FF lines outputs a subset of {0,1,…,p−1}\{0, 1, \dots , p - 1\}, 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