Poj 2034——Anti-prime Sequences
还不解封,人要疯。
Dfs 暴力枚举每一位,似乎没什么好办法,具体看注释吧。
Description
Given a sequence of consecutive integers n,n+1,n+2,…,m, an anti-prime sequence is a rearrangement of these integers so that each adjacent pair of integers sums to a composite (non-prime) number. For example, if n = 1 and m = 10, one such anti-prime sequence is 1,3,5,4,2,6,9,7,8,10. This is also the lexicographically first such sequence.
给定一个连续的整数序列n,n+1,n+2,…,m,反素数序列是这些整数的重新排列,使得每个相邻的整数对和为一个合成(非素数)数。例如,如果n=1,m=10,则一个这样的反素数序列是1,3,5,4,2,6,9,7,8,10。这也是字典顺序上第一个这样的序列。
We can extend the definition by defining a degree danti-prime sequence as one where all consecutive subsequences of length 2,3,…,d sum to a composite number. The sequence above is a degree 2 anti-prime sequence, but not a degree 3, since the subsequence 5, 4, 2 sums to 11. The lexicographically .rst degree 3 anti-prime sequence for these numbers is 1,3,5,4,6,2,10,8,7,9.
我们可以通过定义阶反素数序列来扩展该定义,其中长度为2,3,…,d的所有连续子序列和为一个合成数。上述序列是2次反素数序列,但不是3次反素数序列,因为子序列5、4、2之和为11。这些数的第一个3次反素数序列的词典顺序是1,3,5,4,6,2,10,8,7,9。
INPUT
Input will consist of multiple input sets. Each set will consist of three integers, n, m, and d on a single line. The values of n, m and d will satisfy 1 <= n < m <= 1000, and 2 <= d <= 10. The line 0 0 0 will indicate end of input and should not be processed.
输入将由多个输入集组成。每组由三个整数组成,n、m和d,放在一行。n、m和d的值将满足1 <= n < m <= 1000,和2 <= d <= 10。0 0 0将表示输入结束,不应该被处理。
Output
For each input set, output a single line consisting of a comma-separated list of integers forming a degree danti-prime sequence (do not insert any spaces and do not split the output over multiple lines). In the case where more than one anti-prime sequence exists, print the lexicographically first one (i.e., output the one with the lowest first value; in case of a tie, the lowest second value, etc.). In the case where no anti-prime sequence exists, output
No anti-prime sequence exists.
对于每个输入集,输出一个由逗号分隔的整数列表组成的单行,形成一个度数的反素数序列(不要插入任何空格,不要将输出分成多行)。在存在多个反素数序列的情况下,打印按字母顺序排列的第一个序列(即输出第一个数值最低的序列;在出现并列的情况下,输出第二个数值最低的序列,等等)。在不存在反素数序列的情况下,输出
不存在反素数序列。
Sample Input
1 | 1 10 2 |
Sample Output
1 | 1,3,5,4,2,6,9,7,8,10 |
代码
1 |
|