아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Table 8

시간 제한1초메모리 제한512 MB

요약
N×N 격자를 숫자로 채워 모든 행, 열, 주대각선이 앞자리 0 없이 서로 다른 M의 배수가 되도록 한다.
난이도

보통10점 중 5점

유형
백트래킹, 구현, 완전 탐색
정답자
아직 제출이 없습니다

문제

For the given integer M, build a square table with N rows and N columns (2 ≤ N ≤ 10), filled with decimal digits, with the following restriction: the N-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 M, must not start with the digit 0 and must be unique within the table.

For example, a valid table for M = 2 is

2 3 4
5 6 6
8 2 0

The following tables are not valid for M = 2:

4

because N < 2;

2 0
4 8

because the numbers in the last column and on one of the main diagonals start with the digit 0;

2 3 4
5 8 8
2 0 2

because the number 482 is present twice in the table.

It is not always possible to solve this task. For example, the task is unsolvable for M = 10.

입력

The first line contain one value of M.

출력

The first line of a file must contain N, the number of rows and columns in the table. The i+1-st line of the file (1 ≤ i ≤ N) must contain the elements of the i-th row of the table as N digits, separated by spaces.

제한

M = 137

힌트

It is known that there will be at least one solution for each given test input.

예제1

  1. 예제 1

    입력
    2
    
    예상 출력
    3
    2 3 4
    5 6 6
    8 2 0