Question: A, B, and C are arranged in the remainder of the number N, which satisfies any I (a [I] + B [I]). % N = C [I].
For example, when n = 5, there is a following arrangement:
A: 1 4 3 2 0
B: 1 0 2 4 3
C: 2 4 0 1 3
Solution: first, the arrangement is not unique if it exists, because the same two columns of A, B, and C can be exchanged at will, so that the result is still satisfied. For a given n, we can list a chart:
The vertical and horizontal coordinates reflect the sum of the remainder:
0 1 2 3 4
1 2 3 4 0
2 3 4 0 1
3 4 0 1 2
4 0 1 2 3
Just take the diagonal line from top left to bottom right.
The above only guarantees that there is a solution when n is an odd number, which is not enough to explain why the White even number does not exist. There is another idea that cannot be proved by myself: for every legal situation, A, B, and C must grow according to certain rules, that is, an arithmetic difference series, only N is Modulo for each digit. If the tolerance D is equal to N, all the remainder values can be enumerated in n steps. Otherwise, they cannot.
Evidence: if any sequence starts from 0, the sequence is changed to 0, d % N, 2 * D % n... I * D % n... J * D % n... (N-1) * D % N if Id % N = JD % N exists, then n | (J-I) d Due to gcd (d, n) = 1 and I-j <n, which is obviously absurd. Therefore, any two IDs % N and JD % N are mutually dependent. Because there are n numbers, all the remainder is retrieved, the conclusion cannot be deduced. In fact, as long as J-I = N/gcd (d, n), there will be ID % N = JD % N, obviously, the two remainder numbers are the same.
This is the reason why the tolerances of sequence a and sequence B above are all 1, because the tolerances of the two sequences with the tolerance of 1 are 2 after the addition of the two sequences with the tolerance of 1, and the two and the odd n are mutually dependent. Therefore, you can select more solutions for matching. If the above assumption is true, the even n is also a good negative, because the and B of the even n must have an odd number for both tolerances, for C, the tolerance is changed to an even number, and N is also an even number. Because D is not in interconnectivity, the three sequences cannot be constructed.
What I cannot prove now is that, after sorting a into a sequence of D = 1, B is also required to be an equality sequence.
The Code is as follows:
#include <cstdlib>#include <cstdio>#include <cstring>using namespace std;int main() { int N; while (scanf("%d", &N) != EOF) { if (!(N&1)) { puts("-1"); continue; } for (int i = 0; i < N; ++i) { printf(i == N-1 ? "%d\n" : "%d ", i); } for (int i = 0; i < N; ++i) { printf(i == N-1 ? "%d\n" : "%d ", i); } for (int i = 0; i < N; ++i) { printf(i == N-1 ? "%d\n" : "%d ", 2*i%N); } } return 0; }