Algorithm 版 (精华区)
发信人: Lerry (想不开·撞树), 信区: Algorithm
标 题: IOI'94 - Day 1 - Problem 3: The Primes
发信站: 哈工大紫丁香 (2002年03月29日13:25:18 星期五), 站内信件
IOI'94 - Day 1 - Problem 3: The Primes
|---|---|---|---|---|
| 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 |
|---|---|---|---|---| (Figure 1)
----------------------------------------------------------------------------
----
Figure 1 shows a square. 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 r
ight. Using the data in the INPUT.TXT file, write a program that constructs
such squares.
The prime numbers must have the same digit sum (11 in the example).
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.
A five digit prime number cannot begin with zeros, ie 00003 is NOT a five di
git prime number.
Input Data
The program reads data from the INPUT.TXT file. First the digit sum of prime
numbers and then the digit in the top left-hand corner of the square. The f
ile contains two lines. There will always be a solution to the given test da
ta. In our example:
11
1
Output Data
In the OUTPUT.TXT file, write five lines for each solution found, where each
line in turn consists of a five digit prime number. The above example has 3
solutions which means that the OUTPUT.TXT file contains the following (the
empty lines are optional):
11351
14033
30323
53201
13313
11351
33203
30323
14033
33311
13313
13043
32303
50231
13331
--
不在乎天长地久,就怕你从来没有!
※ 来源:·哈工大紫丁香 bbs.hit.edu.cn·[FROM: 天外飞仙]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:3.176毫秒