Baltic Olympiad in Informatics: 2003 Day 1, Problem 3
For the given integer , build a square table with rows and columns, filled with decimal digits, with the following restriction: the -digit numbers formed by the digits in each table row (from left to right), each table column (from top to bottom) and each main diagonal (from top to bottom) must be multiples of , must not start with the digit and must be unique within the table.
For example, a valid table for is:
The following tables are not valid for :
because ;
because the numbers in the last column and on one of the main diagonals start with the digit ;
because the number is present twice in the table.
It is not always possible to solve this task. For example, the task is unsolvable for .
Constraints
Each cell value must be an integer between and .
Input Specification
The input contains one integer , denoting the number of the current test case.
The input for these ten test cases are found as text files in the attachment below. Each test case file will contain one integer .
For example, if , the input for this test can be found in the file 3.in
.
Output Specification
Output a valid table for test case . This table is guaranteed to exist. The first line of output must contain , the number of rows and columns in the table. The line of the file must contain the elements of the row of the table as space-separated digits.
Grading
You will score points for a test case if there is no output for this test case or if any of the conditions given above are not met.
Otherwise your score for the test case is calculated from the formula:
Therefore, you should try to find a valid table with the least possible size, within the conditions given above.
Sample Input
0
Sample Output
3
2 3 4
5 6 6
8 2 0
Sample Explanation
The input contains , denoting this case's input data can be found in the file 0.in
. 0.in
contains one integer , which means you should output a valid table for .
This table size is not minimized and thus wouldn't yield full points. Note that , this is just the sample case.
Attachment Package
The input files are available here.
Comments