OJ5803 GPT-5.2 Thinking

· · 题解

这题本质是在问:是否存在一个 n 阶群 (S,\times) 以及三个排列 A,B,C,使得对所有 x\in S 都有

A(x)\times B(x)=C(x).

关键等价(把题目化简)

如果存在解,利用 A 是双射,我们可以把元素整体“重命名”(做同构变换),不改变“是否存在解”这个事实,从而 不失一般性地令 A(x)=x。
这样条件变为:

x\times B(x)=C(x),

且 B,C 都是排列。也就是:找一个排列 B,使得映射

x\mapsto x\times B(x)

也是排列。群论里这叫 complete mapping / orthomorphism。

已知结论(Hall–Paige 定理的直接推论):

有限群存在 complete mapping 当且仅当 其 Sylow-2 子群 不是循环的(或 2-部分为 1)。
对应到阶 n 的存在性判定就是:

接下来只要给出 构造 即可。

构造方案

1) n 为奇数:用循环群 \mathbb Z_n

定义:

因为 n 奇数时 2 在模 n 下可逆,所以 x\mapsto 2x 是排列。

2) 4\mid n:用 (\mathbb Z_2)^k \times \mathbb Z_m,其中 n=2^k m,\ m 为奇数,且 k\ge 2

把元素编号为

x = a\cdot m + b,\quad a\in[0,2^k-1],\ b\in[0,m-1]

定义群运算

(a,b)\times(a',b')=(a\oplus a',\ (b+b')\bmod m)

排列取:

其中 \text{mulX}(a) 表示在 GF(2^k) 中乘以 x 的线性双射(用一个固定本原多项式实现)。
这样 a\mapsto \text{mulX}(a) 是排列;同时 a\mapsto a\oplus \text{mulX}(a) 等价于乘以 x+1 也是排列;而 m 为奇数保证 b\mapsto 2b 是排列,所以 B,C 都是排列。

C++ 代码(直接可交,输出乘法表与三行排列)

#include <bits/stdc++.h>
using namespace std;

// primitive/irreducible polynomials for GF(2^k) (standard choices)
// stored as bitmasks including the x^k term.
// k up to 9 is enough; here n <= 500 so k <= 8 actually.
static int primPoly[10] = {
    0, 0,
    0b111,        // k=2:  x^2 + x + 1
    0b1011,       // k=3:  x^3 + x + 1
    0b10011,      // k=4:  x^4 + x + 1
    0b100101,     // k=5:  x^5 + x^2 + 1
    0b1000011,    // k=6:  x^6 + x + 1
    0b10001001,   // k=7:  x^7 + x^3 + 1
    0x11D,        // k=8:  x^8 + x^4 + x^3 + x^2 + 1
    0x211         // k=9:  x^9 + x^4 + 1
};

// multiply by x in GF(2^k) with modulus primPoly[k]
static inline int mulX(int a, int k) {
    int mask = (1 << k) - 1;
    int msb = 1 << (k - 1);
    int poly = primPoly[k] & mask; // drop x^k term
    int res = (a << 1) & mask;
    if (a & msb) res ^= poly;
    return res;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int T;
    cin >> T;
    while (T--) {
        int n;
        cin >> n;

        if (n % 2 == 1) {
            // YES: cyclic group Z_n
            cout << "YES\n";
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    if (j) cout << ' ';
                    cout << (i + j) % n;
                }
                cout << "\n";
            }
            // A = id
            for (int i = 0; i < n; i++) {
                if (i) cout << ' ';
                cout << i;
            }
            cout << "\n";
            // B = id
            for (int i = 0; i < n; i++) {
                if (i) cout << ' ';
                cout << i;
            }
            cout << "\n";
            // C(i)=2i mod n
            for (int i = 0; i < n; i++) {
                if (i) cout << ' ';
                cout << (2LL * i) % n;
            }
            cout << "\n";
        } else if (n % 4 == 2) {
            // NO
            cout << "NO\n";
        } else {
            // YES: n divisible by 4
            // n = 2^k * m, with m odd, k>=2
            int k = 0;
            int tmp = n;
            while ((tmp & 1) == 0) { k++; tmp >>= 1; }
            int m = tmp;                 // odd part
            int pw = 1 << k;             // 2^k
            // build table for group (Z2)^k x Z_m
            cout << "YES\n";
            for (int i = 0; i < n; i++) {
                int ai = (m == 0 ? 0 : i / m);
                int bi = (m == 0 ? 0 : i % m);
                for (int j = 0; j < n; j++) {
                    int aj = (m == 0 ? 0 : j / m);
                    int bj = (m == 0 ? 0 : j % m);
                    int a = ai ^ aj;
                    int b = (m == 1 ? 0 : (bi + bj) % m);
                    int val = a * m + b;
                    if (j) cout << ' ';
                    cout << val;
                }
                cout << "\n";
            }

            // A = id
            for (int i = 0; i < n; i++) {
                if (i) cout << ' ';
                cout << i;
            }
            cout << "\n";

            // B(x) = (mulX(a), b)
            for (int x = 0; x < n; x++) {
                int a = (m == 0 ? 0 : x / m);
                int b = (m == 0 ? 0 : x % m);
                int a2 = mulX(a, k);
                int bx = a2 * m + b;
                if (x) cout << ' ';
                cout << bx;
            }
            cout << "\n";

            // C(x) = x * B(x) = (a xor mulX(a), 2b mod m)
            for (int x = 0; x < n; x++) {
                int a = (m == 0 ? 0 : x / m);
                int b = (m == 0 ? 0 : x % m);
                int a2 = mulX(a, k);
                int a3 = a ^ a2;
                int b3 = (m == 1 ? 0 : (2LL * b) % m);
                int cx = a3 * m + b3;
                if (x) cout << ' ';
                cout << cx;
            }
            cout << "\n";
        }
    }
    return 0;
}

这个程序满足:

如果你还想把证明写得更“比赛友好”(不引用 Hall–Paige 名字、只写结论与直观说明),我也可以帮你把题解文字润色成可直接提交到博客/题解区的版本。