跳到正文

题解

CF2037C Superultra's Favorite Permutation tj

_colin1112_约 2 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2025年12月12日
篇幅
约 2 分钟
题目
CF2037C

版本

  1. v1当前

思路

构造题。

大概意思就是构造数列 pp,使得对于 1≤i≤n−11 \leq i \leq n - 1,ai+ai+1a_i + a_{i + 1} 不是素数。

易证当 n≤4n \leq 4 时,无解。

因为偶数 + 偶数 = 偶数,奇数 + 奇数 = 偶数。所以在数列左边放偶数,右边放奇数即可。但是在偶数和奇数在接口处可能会出现素数,于是在偶数与奇数处放 4 和 5 作为接口即可。

Code

C++
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'

using namespace std;
const int E = 1e6 + 5;
ll t;
ll x;
int main()
{
    cin >> t;
    while (t--)
    {
        cin >> x;
        if (x <= 4)
        {
            cout << -1 << endl;
            continue;
        }
        for (int i = 2; i <= x; i += 2)
            if (i != 4)
                cout << i << ' ';
        cout << "4 5 ";
        for (int i = 1; i <= x; i += 2)
            if (i != 5)
                cout << i << ' ';
        cout << endl;
    }
    return 0;
}
原文