10432 - 素数方阵

在下面的方格中,每行,每列,以及两条对角线上的数字可以看作是五位的素数。方格中的行按照从左到右的顺序组成一个素数,而列按照从上到下的顺序。两条对角线也是按照从左到右的顺序来组成。

+---+---+---+---+---+

| 1 | 1 | 3 | 5 | 1 |

| 3 | 3 | 2 | 0 | 3 |

+---+---+---+---+---+

| 3 | 0 | 3 | 2 | 3 |

+---+---+---+---+---+

| 1 | 4 | 0 | 3 | 3 |

+---+---+---+---+---+

| 3 | 3 | 3 | 1 | 1 |

+---+---+---+---+---+

这些素数各个数位上的和必须相等。 左上角的数字是预先定好的。 一个素数可能在方阵中重复多次。 如果不只有一个解,将它们全部输出(按照这25个数字组成的25位数的大小排序)。 一个五位的素数开头不能为0(例如:00003 不是五位素数)

输入

一行包括两个被空格分开的整数:各个位的数字和 和左上角的数字。

输出

对于每一个找到的方案输出5行,每行5个字符, 每行可以转化为一个5位的质数.在两组方案中间输出一个空行. 如果没有解就单独输出一行"NONE"。

样例

输入

11 1

输出

11351
14033
30323
53201
13313

11351
33203
30323
14033
33311

13313
13043
32303
50231
13331

提示

IOI'94 In the square below, each row, each column and the two diagonals can be read as a five digit prime number. The rows are read from left to right. The columns are read from top to bottom. Both diagonals are read from left to right.

+---+---+---+---+---+ | 1 | 1 | 3 | 5 | 1 | +---+---+---+---+---+ | 3 | 3 | 2 | 0 | 3 | +---+---+---+---+---+ | 3 | 0 | 3 | 2 | 3 | +---+---+---+---+---+ | 1 | 4 | 0 | 3 | 3 | +---+---+---+---+---+ | 3 | 3 | 3 | 1 | 1 | +---+---+---+---+---+

The prime numbers' digits must sum to the same number. The digit in the top left-hand corner of the square is pre-determined (1 in the example). A prime number may be used more than once in the same square. If there are several solutions, all must be presented (sorted in numerical order as if the 25 digits were all one long number). A five digit prime number cannot begin with a zero (e.g., 00003 is NOT a five digit prime number). PROGRAM NAME: prime3 INPUT FORMAT A single line with two space-separated integers: the sum of the digits and the digit in the upper left hand corner of the square.

SAMPLE INPUT (file prime3.in) 11 1

OUTPUT FORMAT Five lines of five characters each for each solution found, where each line in turn consists of a five digit prime number. Print a blank line between solutions. If there are no prime squares for the input data, output a single line containing "NONE".

SAMPLE OUTPUT (file prime3.out) The above example has 3 solutions.

11351 14033 30323 53201 13313

11351 33203 30323 14033 33311

13313 13043 32303 50231 13331

时间限制 1 秒
内存限制 128 MB
统计
上一题 下一题