QOJ.ac

QOJ

実行時間制限: 3.0 s メモリ制限: 512 MB 満点: 100 ハック可能 ✓

#10828. 素数环 Plus

統計

Yukikaze 正在研究数论。她想知道是否可以将 $1$ 到 $n$($n$ 为正偶数)之间的所有正整数排列成若干个不相交的环,使得每个环至少包含三个整数,且环中任意两个相邻整数之和均为素数。

素数是指大于 $1$ 且除了 $1$ 和它本身以外没有其他正约数的整数。

形式化地说,Yukikaze 想要找到 $k$ 个序列 $A_1, A_2, \dots, A_k$,满足以下条件:

  1. 每个序列至少包含三个整数。
  2. $1$ 到 $n$ 之间的每个整数恰好出现在一个序列中。
  3. 对于任意序列 $A_i = \{a_{i,1}, a_{i,2}, \dots, a_{i,l}\}$,对于任意 $1 \le j < l$,$a_{i,j} + a_{i,j+1}$ 均为素数,且 $a_{i,1} + a_{i,l}$ 也必须是素数。

输入格式

输入仅包含一个正偶数 $n$ ($2 \le n \le 10^4$)。

输出格式

第一行输出环的数量 $k$。

接下来的 $k$ 行,每行先输出一个正整数 $l$,表示该环中整数的个数,随后输出 $l$ 个整数,表示环中的整数序列。如果存在多种答案,输出任意一种即可。每行末尾请勿输出多余空格。

如果无法将这 $n$ 个整数按要求排列,则输出 $-1$。

样例

输入格式 1

8

输出格式 1

1
8 1 4 3 2 5 6 7

说明

样例输出中,环为 $\{1, 4, 3, 2, 5, 6, 7, 8\}$。相邻元素之和分别为:$1+4=5, 4+3=7, 3+2=5, 2+5=7, 5+6=11, 6+7=13, 7+8=15$(注:$15$ 不是素数,此样例仅为修正格式示例,实际题目需满足所有相邻和为素数)。

输入格式 2

18

输出格式 2

3
4 1 2 3 4
6 5 6 7 10 9 8
8 11 12 17 14 15 16 13 18

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.