#C11941. Knight's Tour on a Chessboard
Knight's Tour on a Chessboard
Knight's Tour on a Chessboard
Given an integer \( n \), determine whether a knight can visit every cell of an \( n \times n \) chessboard exactly once, using standard knight moves. A knight's move is an L-shaped move: two squares in one direction and then one square perpendicular to it.
For \( n = 1 \), the answer is trivially YES
. For boards where \( n \) is less than 5 (except for \( n = 1 \)), it is impossible for the knight to tour the board exactly once, so the answer is NO
. For \( n \geq 5 \), it is known that a knight's tour exists, thus the answer is YES
.
You are to write a program that reads an integer from standard input and outputs YES
if the knight's tour is possible, or NO
otherwise.
The mathematical condition can be summarized as:
\[ \text{if } n = 1 \rightarrow YES, \quad \text{if } 2 \leq ninputFormat
The input consists of a single line containing one integer ( n ) (where ( 1 \leq n \leq 10^5 ) for practical constraints).
outputFormat
Output a single line containing either "YES" if the knight can visit every cell of the board exactly once, or "NO" otherwise.## sample
1
YES