eolymp
bolt
Try our new interface for solving problems

N Queens

\includegraphics{https://static.e-olymp.com/content/ec/ecd4bd153808be123a06b29203bd7283b1d7bea9.jpg} There is well‐known task to place \textbf{8} chess queens on the original \textbf{8}×\textbf{8 }chessboard in a way that no two of them attack each other. A queen attacks all cells that are in the same row, same column or same diagonal with it. One of the solutions is shown on the figure. The generalised problem was posed by Franz Nauck in \textbf{1850} and asks in how many ways \textbf{N} queens can be placed on an \textbf{N}×\textbf{N} board so tht no two queens attack each other. It has been proven that for \textbf{N}>\textbf{3} there always exists at least one solution. For example, for \textbf{N=26} there are \textbf{22317699616364044} different solutions. You are asked to solve a slightly different task -- find any one solution (correct placement of \textbf{N} queens on an \textbf{N}×\textbf{N} board) for five given values of \textbf{N }and submit an output file for each solution: \InputFile One number - \textbf{N (N ≤ 10^5)}. (see example) \OutputFile In the output file with the specified name there must be \textbf{N} rows. For each \textbf{i }(\textbf{1} ≤ \textbf{i} ≤ \textbf{N}) the \textbf{i}‐th row of the output file must contain exactly one integer -- the number of the column where the queen in the \textbf{i}‐th row is placed. For example, if you would be asked to submit a solution for eight queens, then a valid output file content might be (corresponds to the picture above; rows are numbered from top to bottom, columns are numbered from left to right) - see example.
Zaman məhdudiyyəti 30 saniyə
Yaddaşı istafadə məhdudiyyəti 64 MiB
Giriş verilənləri #1
26
Çıxış verilənləri #1
20
3
16
6
17
5
11
4
15
7
22
1
21
23
10
26
24
18
12
8
19
25
9
14
2
13
Mənbə BOI-2012